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

Incorrect type inference in 'match' expression #727

Closed
developedby opened this issue Oct 9, 2024 · 2 comments
Closed

Incorrect type inference in 'match' expression #727

developedby opened this issue Oct 9, 2024 · 2 comments

Comments

@developedby
Copy link
Member

developedby commented Oct 9, 2024

Reproducing the behavior

Considering the following program

type Box:
  Box {x: Unit}

type Unit:
  Unit

Erase: Box -> None
(Erase (Box/Box x)) = (Erase x)

main: None
main = (Erase (Box/Box Unit/Unit))

This should generate a type error in the Erase function, since it expects a Box value but we're giving it a Unit.

Based on the match expression, the type of Erase should be Box -> var, while according to the call it should be Unit -> var. When unifying these two we expect a type error, which never happens.

The final infered type is Box -> var, which specializes to Box -> None when checking against the annotation.

System Settings

Bend commit: 4d6f461

Additional context

No response

@developedby
Copy link
Member Author

The issue was that the type constructors inside of constructor fields were not being resolved and were kept as variables. So, even though the type of the Box/Box constructor was being updated to Unit -> Box with Unit as a constructor, the type of x was still Unit as a type variable.

This means that all fields inside of match expressions were being inferred variable types for the nullary constructors in their types.

@developedby
Copy link
Member Author

Fixed by #728

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