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

Emit error for duplicate type parameters #40

Closed
fo5for opened this issue Dec 9, 2021 · 1 comment · Fixed by #44
Closed

Emit error for duplicate type parameters #40

fo5for opened this issue Dec 9, 2021 · 1 comment · Fixed by #44
Assignees
Labels
bug Something isn't working

Comments

@fo5for
Copy link
Collaborator

fo5for commented Dec 9, 2021

class Test[A, A]: { x: A }
//│ Defined class Test

t = Test { x = 42 }
//│ t: Test['A | 'A0 .. 42 & 'A | 'A & 'A0, 'A | 'A0 .. 42 & 'A | 'A & 'A0] with {x: 42}

t : Test[bool, int]
//│ res: Test[bool | int .. nothing, bool | int .. nothing]

t : Test[int, bool]
//│ ╔══[ERROR] Type mismatch in type ascription:
//│ ║  l.10: 	t : Test[int, bool]
//│ ║        	^
//│ ╟── expression of type `42` does not match type `bool`
//│ ║  l.4: 	t = Test { x = 42 }
//│ ║       	               ^^
//│ ╟── but it flows into reference with expected type `Test[int, bool]`
//│ ║  l.10: 	t : Test[int, bool]
//│ ║        	^
//│ ╟── Note: constraint arises from type reference:
//│ ║  l.10: 	t : Test[int, bool]
//│ ║        	              ^^^^
//│ ╟── from record type:
//│ ║  l.1: 	class Test[A, A]: { x: A }
//│ ╙──     	                  ^^^^^^^^
//│ res: Test[bool | int .. nothing, bool | int .. nothing]

Currently the last one takes precedence, and the output contains duplicate type variables. (It breaks surprisingly few things besides ascription.)

@fo5for fo5for added the bug Something isn't working label Dec 9, 2021
@LPTK
Copy link
Contributor

LPTK commented Dec 10, 2021

Right. BTW we have the same problem with record fields, although I'm not sure it breaks anything:

aa = {a = 1; a = "oops" }
//│ aa: {a: 1, a: "oops"}

aa.a
//│ res: 1

aa: { a: 'a }
//│ res: {a: 1}

Do you think you can fix them after we've merged my PR?

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

Successfully merging a pull request may close this issue.

2 participants