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

Simplification bug with methods and type parameters #114

Open
fo5for opened this issue Jun 27, 2022 · 1 comment
Open

Simplification bug with methods and type parameters #114

fo5for opened this issue Jun 27, 2022 · 1 comment
Labels
bug Something isn't working simplification

Comments

@fo5for
Copy link
Collaborator

fo5for commented Jun 27, 2022

Discovered in c87010f.

:NoJS

class Some[a]: { val: a }
  method Get: a
//│ Defined class Some[+a]
//│ Declared Some.Get: Some['a] -> 'a

// simplification bug here
def g x = (x.Get 0, x.Get "a")
//│ g: Some[nothing -> ('a | 'b)] -> ('b, 'a,)

g (error: Some[nothing -> 0])
//│ ╔══[ERROR] Type mismatch in application:
//│ ║  l.12: 	g (error: Some[nothing -> 0])
//│ ║        	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ╟── string literal of type `"a"` does not match type `nothing`
//│ ║  l.9: 	def g x = (x.Get 0, x.Get "a")
//│ ║       	                          ^^^
//│ ╟── Note: constraint arises from type reference:
//│ ║  l.12: 	g (error: Some[nothing -> 0])
//│ ╙──      	               ^^^^^^^
//│ res: (0, 0,) | error

// expected behavior
def g (x: Some['a]) = (x.val 0, x.val "a")
//│ g: Some["a" -> 'a & 0 -> 'b] -> ('b, 'a,)

g (error: Some[nothing -> 0])
//│ ╔══[ERROR] Type mismatch in application:
//│ ║  l.28: 	g (error: Some[nothing -> 0])
//│ ║        	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ╟── string literal of type `"a"` does not match type `nothing`
//│ ║  l.25: 	def g (x: Some['a]) = (x.val 0, x.val "a")
//│ ║        	                                      ^^^
//│ ╟── Note: constraint arises from type reference:
//│ ║  l.28: 	g (error: Some[nothing -> 0])
//│ ╙──      	               ^^^^^^^
//│ res: (0, 0,) | error

In the first definition of g using x.Get, the inferred type is erroneously printed with a nothing. This appears to be a simplification bug since actually passing something of the function parameter type to g results in an error. The error message also refers to type "a", which does not appear in the printed type of g. The expected behavior should be identical to the second definition of g using x.val.

@fo5for fo5for added bug Something isn't working simplification labels Jun 27, 2022
@LPTK
Copy link
Contributor

LPTK commented Jun 27, 2022

Thanks for reporting. Do you want to try your hand on it? (After the POPL deadline ofc.) You can see what's going on using the debug-simplification command :ds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working simplification
Projects
None yet
Development

No branches or pull requests

2 participants