Disallow non-invariant types in Pointer#value=
#7225
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #6997
The code in #6997 shouldn't compile at all, as I explained in the issue.
This PR changes
Pointer#value=
to disallow non-invariant types. If you have aPointer(Array(String | Int32))
then you must insert anArray(String | Int32)
into it. You can't insertArray(String)
orArray(Int32)
.As a second step to this I would like to change all restrictions to always check invariance for generic types. Right now we can do
x : Range(Int, Int)
as a type restriction to say "any type that inheritsInt
" but that gives the problem of #6997. We can change the semantic to mean "must be anInt
" (in this case it doesn't make sense) and eventually introduce some syntax to mean "must be anInt
or inherit it".