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

Match types: fix wildcard captures handling to match intent. #77

Merged

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Feb 6, 2024

As demonstrated by scala/scala3#19607, picking H does not in fact always work. It was always the intent of the spec to pick an instantiation that would make subtyping work, but the particular choice was wrong.

IMO this is therefore clearly a spec bug, and we can address it irrespective of compatibility concerns.


Companion PR to fix it in the compiler: scala/scala3#19627

As demonstrated by scala/scala3#19607,
picking `H` does *not* in fact always work. It was always the
intent of the spec to pick an instantiation that would make
subtyping work, but the particular choice was wrong.

IMO this is therefore clearly a spec bug, and we can address it
irrespective of compatibility concerns.
odersky added a commit to scala/scala3 that referenced this pull request Feb 15, 2024
…ds. (#19627)

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
@anatoliykmetyuk anatoliykmetyuk merged commit e66ab23 into scala:main Feb 20, 2024
@sjrd sjrd deleted the match-types-fix-wildcard-capture-logic branch February 20, 2024 10:31
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.

2 participants