Skip to content
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

Polymorphic functions that pull record items aren't constraining the result type properly #57

Closed
j14159 opened this issue Dec 1, 2016 · 1 comment

Comments

@j14159
Copy link
Collaborator

j14159 commented Dec 1, 2016

The following three tests fail, we should expect that a get_x not returning an option won't unify with my_map/2's second argument and thus fail but the typer accepts the integer argument instead of rejecting it. I have not yet confirmed or denied that this behaviour is limited to records.

    , fun() ->
              Code =
                  "module fun_pattern_with_adt\n\n"
                  "type option 'a = None | Some 'a\n\n"
                  "my_map _ None = None\n\n"
                  "my_map f Some a = Some (f a)\n\n"
                  "doubler x = x * x\n\n"
                  "foo = my_map doubler 2",
              ?assertMatch(
                 {error, {cannot_unify, _, _, #adt{}, t_int}},
                 module_typ_and_parse(Code))
      end
    , fun() ->
              Code =
                  "module fun_pattern_with_adt\n\n"
                  "type option 'a = None | Some 'a\n\n"
                  "my_map _ None = None\n\n"
                  "my_map f Some a = Some (f a)\n\n"
                  "doubler x = x * x\n\n"
                  "get_x {x=x} = x\n\n"
                  "foo () = "
                  "  let rec = {x=1, y=2} in "
                  "  my_map doubler (get_x rec)",
              ?assertMatch(
                 {error, {cannot_unify, _, _, #adt{}, t_int}},
                 module_typ_and_parse(Code))
      end
    , fun() ->
              Code =
                  "module fun_pattern_with_adt\n\n"
                  "type option 'a = None | Some 'a\n\n"
                  "my_map _ None = None\n\n"
                  "my_map f Some a = Some (f a)\n\n"
                  "doubler x = x * x\n\n"
                  "get_x rec = match rec with {x=x} -> x\n\n"
                  "foo () = "
                  "  let rec = {x=1, y=2} in "
                  "  my_map doubler (get_x rec)",
              ?assertMatch(
                 {error, {cannot_unify, _, _, #adt{}, t_int}},
                 module_typ_and_parse(Code))
      end
j14159 added a commit that referenced this issue Dec 1, 2016
Filed bug #57 as the typer bug isn't limited to function arg patterns.
@j14159 j14159 mentioned this issue Dec 5, 2016
@j14159
Copy link
Collaborator Author

j14159 commented Dec 7, 2016

Closing as fixed.

@j14159 j14159 closed this as completed Dec 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant