Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use upper bound of effectively sealed abstract types in exhaustivity checking #23909

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

Open
nox213 wants to merge 3 commits into scala:main
base: main
Choose a base branch
Loading
from nox213:fix/i23620

Conversation

Copy link
Contributor

@nox213 nox213 commented Sep 12, 2025
edited
Loading

closes #23620

If the upper bound of an abstract type is not sealed but is effectively sealed, it is not handled correctly, since classSym could return a type that is not sealed (Object in the issue above).
If the type were not abstract, it would pass the logic that checks whether it is an Or, And, etc., and would be handled properly.
This PR makes exhaustivity checking use the upper bound of abstract types that are effectively sealed.

classSym.is(Case) ||
(tpw.isInstanceOf[TypeRef] && {
val tref = tpw.asInstanceOf[TypeRef]
tref.symbol.isOpaqueAlias && !tref.info.hiBound.isNothingType
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I extract this logic into a separate function? If so, where would be a good place to put it?

else NoType
}.filter(_.exists)
parts
case tref: TypeRef if tref.symbol.isOpaqueAlias && !tref.info.hiBound.isNothingType =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of this logic should be limited to opaque type aliases. It should work also for abstract type members, or not work for either. From the outside of its scope, an opaque type alias is an abstract type member. It makes no sense to treat them differently in this situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c70aaa3
Is this correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems correct to me, as far as that comment is concerned.

I cannot vouch for the whole PR. I am not familiar with pattern-match analysis.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you for the review.

@nox213 nox213 changed the title (削除) Enable exhaustivity and reachability checks for opaque types (削除ここまで) (追記) Use upper bound of effectively sealed abstract types in exhaustivity checking (追記ここまで) Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@sjrd sjrd sjrd left review comments

@hamzaremmal hamzaremmal Awaiting requested review from hamzaremmal

@zielinsky zielinsky Awaiting requested review from zielinsky

At least 1 approving review is required to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

False pattern match not exhaustive for union types + opaque types

AltStyle によって変換されたページ (->オリジナル) /