You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7420 Reporter:@johnwhitington Status: resolved (set by @xavierleroy on 2017-02-19T17:27:02Z) Resolution: suspended Priority: normal Severity: minor Category: typing
Bug description
Type annotations on labelled or optional arguments in .ml files are thrown away without warning:
let f ?x:int y = y;;
val f : ?x:'a -> 'b -> 'b =
let f ~x:int y = y;;
val f : x:'a -> 'b -> 'b =
The labelled one should be used in the normal way, to restrict the type and the optional one should be rejected, not being an option type, surely? It seems odd to silently drop them.
Additional information
For reference, for anyone as easily confused as me, here is a .mli/.ml pair which typechecks for such a function
val f : ?x:int -> 'a -> 'a
let f ?(x : int option) y = y
The option-ness of the type of 'x' is implicit in the .mli, explicit in the .ml.
The text was updated successfully, but these errors were encountered:
The first definition is properly rejected by ocamlc -i:
$cat labels.ml
let f ?x:int y = y;;
$ ocamlc -i labels.ml
File "labels.ml", line 1, characters 8-13:
Error: This pattern matches values of type int
but a pattern was expected which matches values of type 'a option
It's an unfortunate similarity, but I don't think anything can be done at this point.
That sounds awkward, but maybe we could warn if the identifier chosen happens to be one of the built-in non-parameterized types of the language? (I don't think that int, char or bool are commendable identifier names anyway.)
Original bug ID: 7420
Reporter: @johnwhitington
Status: resolved (set by @xavierleroy on 2017-02-19T17:27:02Z)
Resolution: suspended
Priority: normal
Severity: minor
Category: typing
Bug description
Type annotations on labelled or optional arguments in .ml files are thrown away without warning:
let f ?x:int y = y;;
val f : ?x:'a -> 'b -> 'b =
let f ~x:int y = y;;
val f : x:'a -> 'b -> 'b =
The labelled one should be used in the normal way, to restrict the type and the optional one should be rejected, not being an option type, surely? It seems odd to silently drop them.
Additional information
For reference, for anyone as easily confused as me, here is a .mli/.ml pair which typechecks for such a function
val f : ?x:int -> 'a -> 'a
let f ?(x : int option) y = y
The option-ness of the type of 'x' is implicit in the .mli, explicit in the .ml.
The text was updated successfully, but these errors were encountered: