New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optional parameters and non generalizable type variables #6899
Comments
Comment author: @trefis Hmmm, the example can actually be cleaned. type 'a t = 'a option let test ?x () = is_some x |
Comment author: @garrigue Thanks for finding a solution. I'm willing to merge it, but I have a question: how do I get a patch from your pull request? |
Comment author: @trefis
Yes, exactly.
I just attached the patch here, it is pr6899.patch |
Comment author: @trefis And git decided to add colors to the diff... The proper patch is pr6899-color=never.patch ... |
Comment author: @trefis Thank you for merging and adding a test!
are now correctly rejected, while they weren't previously. Note: The piece of code given in example here is also accepted on 4.02.2. I don't know if people are considering doing another minor release at some point, but if yes then the patches should probably be backported on that branch. |
Comment author: @garrigue Merged the patch at revision 16184 and the extra tests at revision 16190. |
Original bug ID: 6899
Reporter: @trefis
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-02-16T14:15:11Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.03.0+dev / +beta1
Target version: 4.03.0+dev / +beta1
Fixed in version: 4.03.0+dev / +beta1
Category: typing
Bug description
With trunk programs using optional parameter sometimes fail to type check.
Here is a smallest reproducible example I have:
$ cat test.ml
module Option : sig
type 'a t = 'a option
val is_some : 'a t -> bool
end = struct
type 'a t = 'a option
let is_some = function
| None -> false
| Some _ -> true
end
let test ?x () = Option.is_some x
$ ocamlc test.ml
File "test.ml", line 11, characters 9-33:
Error: The type of this expression, ?x: -> unit -> bool,
contains type variables that cannot be generalized
N.B. this only happens with trunk, 4.02 is fine; it doesn't happen in the toplevel.
There are two problems here (though probably a single root):
1/ The type of [x] contains variables that cannot be generalized.
This is probably related to #5663 and the consequent changes.
2/ The type of ?x is not printed, instead we get .
Meaning: printtyp doesn't know [x] is an option.
File attachments
The text was updated successfully, but these errors were encountered: