Fix #19607: Allow to instantiate *wildcard* type captures to TypeBounds. #19627
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.
When matching in a match type, if we encounter a
TypeBounds
scrutinee and we have a wildcard capture on the right, we used to pick thehi
bound "because anything between betweenlo
andhi
would work".It turns out that nothing between
lo
andhi
works when the type constructor is invariant. Instead, we must be keep the type bounds, and instantiate the wildcard capture to a wildcard type argument.This is fine because a wildcard capture can never be referred to in the body of the case. However, previously this could never happen in successful cases, and we therefore used the presence of a
TypeBounds
in theinstances
as the canonical signal for "fail as not specific". We now use a separatenoInstances
list to be that signal.This change departs from the letter of the spec but not from its spirit. As evidenced by the wording, the spec always intended for "the pick" to one that would always succeed. We wrongly assumed
hi
was always working.Companion PR to fix the spec/SIP: scala/improvement-proposals#77