-
Notifications
You must be signed in to change notification settings - Fork 116
feat: Infer invariant when bound is isolated (no proper super/subtypes except Top/Bottom) #5359
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
Conversation
…contain the unused
At first glance this looks very nice! How do you feel about it? |
Curious if the example from #5036 now works. |
I feel good about it, I think this is a good change 😄 |
I've just added a test for it, and yes it does infer now, because the bound was |
@christoph-dfinity whaddya think? I like it...but maybe you can see a downside. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes look good. I think I can follow the reasoning and motivation as well, so LGTM!
Allow inference of invariant type variables when the solution has no proper subtypes nor supertypes (except Top/Bottom).
After:
Before:
Since the result of the
map
function is a mutable array, the type variable in the result is invariant. This causes the following error:The compiler complains that it cannot solve
U
as, for example, bothText
andAny
would fit but they are not equivalent, andU
is invariant so the choice matters.IMO, considering
Any
as the solution forU
is impractical and users would be better off not providing type instantiations in such cases.However, there is danger in allowing arbitrary types as solutions for invariant type variables, so I propose we restrict these types to "isolated" types (types that have no proper subtypes nor supertypes except Top/Bottom). See the tests for more examples.