Closed Merovius closed 2 years ago
CC @griesemer
Appears to be a problem in the type checker. It seems like this should work; if it doesn't work, it definitely needs a better error message.
This appears to be an evaluation/type-checking ordering problem caused by the mutually referencing types. Moving the declaration of type Y
to the beginning "solves" the problem: https://go2goplay.golang.org/p/h4tcdkyvm2N .
This (and related issues) require some significant re-engineering of the type-checker. Probably won't address in the prototype, in favor of spending engineering effort on a real implementation. Leaving open so we have a test case.
Not only does the prototype no longer matter, this also build now, so closing.
What did you do?
Tried to compile this program (playground link):
What did you expect to see?
No output, as in this program (playground link):
What did you see instead?
Compiler error:
I tried to minimize the code as much as possible, that's why the original intent is a bit obscured.
I suspect that this is a bug in the prototype - at least I see no reason why it would work with
func(*A(T))
, but not withY(T)
. I thought it might be an issue with recursive generic types (A(T)
mentionsX(T)
mentionsY(T)
mentionsA(T)
), but it should fulfill the requirement of only mentioning the original parameters in the same order. And I wouldn't understand why the error is reported in the assignment and why it vanishes when you delete that. In any case, the error message is, of course, not super helpful :)I'd be interested to know if this is WAI or a limitation of the prototype.