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

Fix #19607: Allow to instantiate *wildcard* type captures to TypeBounds. #19627

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Feb 6, 2024

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 the hi bound "because anything between between lo and hi would work".

It turns out that nothing between lo and hi 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 the instances as the canonical signal for "fail as not specific". We now use a separate noInstances 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

…eBounds.

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 the `hi` bound "because anything between between `lo` and
`hi` would work".

It turns out that *nothing* between `lo` and `hi` 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 the `instances` as the canonical signal for
"fail as not specific". We now use a separate `noInstances` 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.
@odersky odersky merged commit fc593df into scala:main Feb 15, 2024
19 checks passed
@odersky odersky deleted the fix-i19607 branch February 15, 2024 16:05
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants