Skip to content

proposal: enable warning 6 ([labels-omitted]) by default #10118

@gasche

Description

@gasche

OCaml understands full unlabelled application of labelled functions, but emits warning 6 ([labels-omitted]). This warning is not enabled by default -- but it is part of the Dune default warnings, so in practice it is the default for a large part of the userbase today.

I believe that the reason for not enabling it by default comes from a "transitory" period when labelled functions were introduced. I don't see a good reason today to keep encouraging this programming style.

On the other hand, when an API designer uses label, they generally consider that their users will have to use them; it is used to clarify caller-side code, and in particular to avoid the programming error of mistakenly swapping arguments of compatible type. Encouraging non-labelled applications weakens these benefits.

This suggestion originates from #10105, which considers replacing a non-labelled function with a labelled function using a different argument order. Currently (with warning 6 disabled by default), non-labelled callsites will keep compiling just fine, even if they forgot to fix the argument order, leading to silent bugs introduced by innocuous refactorings.

(* Declaration, before: *)
let starts_with str sub = String.sub str 0 (String.length sub)

(* Declaration, after: *)
let starts_with ~sub str = String.sub str 0 (String.length sub)

(* This changes silently breaks this code *)
let is_prompt line = starts_with line "#"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions