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: 6611 Reporter:@whitequark Assigned to:@garrigue Status: closed (set by @xavierleroy on 2016-12-07T10:47:00Z) Resolution: fixed Priority: normal Severity: minor Target version: 4.02.2+dev / +rc1 Fixed in version: 4.03.0+dev / +beta1 Category: ~DO NOT USE (was: OCaml general) Related to:#6367 Monitored by:@gasche@diml
Bug description
Currently, the types of all optional arguments in function signatures must be wrapped in an internal "predef option" type, which can be done with this function:
let wrap_predef_option typ =
let predef_option = mknoloc (Ldot (Lident "*predef*", "option")) in
Typ.constr predef_option [typ]
This is extremely unintuitive. The compiler will normally show types not wrapped in "predef option" as "" and complain that the function does not match its signature. In fact, it cost me an hour of debugging before I accidentally looked at Pprintast and noticed an assertion that checks for "predef option".
There are two ways to fix this that I can see.
Proper way. Remove the notion of "predef option" from Parsetree entirely. "?" at the start of the label already carries all the necessary information.
Workaround. Make Typ.arrow look at label and automatically wrap the type in "predef option" if it starts with "?".
I'd go for 1), which is technically very simple: just move the code which adds the predef.option wrapper from parser.mly to typetexp.ml/typeclass.ml (in the cases for Ptyp_arrow/Pcty_arrow). But this cannot be done lightly, since it would break for instance camlp4/camlp5. One more backward compatible change would be to add the wrapper only if it is not already present in the Parsetree.
I've added a patch which does that (untested), but this seems too risky to go into 4.02.1.
I committed this in trunk, at revision 15738, but without the compatibility provision, since I have just exhauced 6367 which is incompatible at the type level anyway.
Original bug ID: 6611
Reporter: @whitequark
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2016-12-07T10:47:00Z)
Resolution: fixed
Priority: normal
Severity: minor
Target version: 4.02.2+dev / +rc1
Fixed in version: 4.03.0+dev / +beta1
Category: ~DO NOT USE (was: OCaml general)
Related to: #6367
Monitored by: @gasche @diml
Bug description
Currently, the types of all optional arguments in function signatures must be wrapped in an internal "predef option" type, which can be done with this function:
This is extremely unintuitive. The compiler will normally show types not wrapped in "predef option" as "" and complain that the function does not match its signature. In fact, it cost me an hour of debugging before I accidentally looked at Pprintast and noticed an assertion that checks for "predef option".
There are two ways to fix this that I can see.
Proper way. Remove the notion of "predef option" from Parsetree entirely. "?" at the start of the label already carries all the necessary information.
Workaround. Make Typ.arrow look at label and automatically wrap the type in "predef option" if it starts with "?".
File attachments
The text was updated successfully, but these errors were encountered: