-
Notifications
You must be signed in to change notification settings - Fork 86
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
Assertion failed on mutual recursion with optional arguments #1001
Comments
I cannot reproduce this bug with the |
Hmm, this is still failing on 2.4.1 for me. |
Slightly smaller test case: type t = int option
let rec f ?(optional : t) () = f ?optional () So, this turns out to be quite interesting. The problem is that we're reading the type of the function, and have found an optional argument. We then ask for the representation of the type and expect to find a let arg =
if Btype.is_optional lbl then
match Compat.get_desc (Compat.repr arg) with
| Tconstr(_option, [arg], _) -> read_type_expr env arg
| _ -> assert false
else read_type_expr env arg In this case, we're finding the constructor In a further test, the following did not fail: type t = int option
let rec f ?(optional : t) () = () |
It'd be handy to have someone who knows how the compiler handles this for an opinion - @Octachron, would you be able to take a look and suggest how to handle this? |
At first glance, the current code is too syntactic. The compiler version (which may also fail in corner cases(?)) looks like this: let extract_option_type env ty =
match get_desc (expand_head env ty) with
Tconstr(path, [ty], _) when Path.same path Predef.path_option -> ty
| _ -> assert false The important difference is the |
Hum, I don't have an |
Minimal example and triggered assertion:
Type annotations avoid hitting the assertion:
The text was updated successfully, but these errors were encountered: