Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Jan 17, 2023

The previous check, meant to address #15618, tested whether all alternatives of a match type had the same classtag and only then permitted a classtag for the match type. This was the wrong test. It did not work for recursive match types, because it could lead to stack overflow for them. And it did not take into account that match types could be reduced.

A better test is to simply declare that match types themselves don't have a stable erasure, just like TypeBounds don't have a stable erasure. If we find an applied type with a match type as definition, we proceed to its translucent supertype, which will try a match type reduction. If that succeeds we produce the classtag of the redux. If not, we end up with an unreduced matchtype and refuse to generate a classtag for it.

Fixes #16706
Fixes #16707

The previous check, meant to address scala#15618, tested whether all alternatives
of a match type had the same class tag and only then permitted a classtag
for the match type. This was the wrong test. It did not work for recursive
match types, because it could lead to stack overflow for them. And it did
not take into account that match types could be reduced.

A better test is to simply declare that match types themselves don't have a stable
erasure, just like TypeBounds don't have a stable erasure. If we find an applied
type with a match type as definition, we proceed to its translucent superytype,
which will try a match type reduction. If that succeeds we produce the classtag
of the redux. If not, we end up with an unreduced matchtype and refuse to generate
a classtag for it.

Fixes scala#16706
Fixes scala#16707
@odersky odersky changed the title Fix check whether classTag can be generated for match types Fix check whether classtag can be generated for match types Jan 17, 2023
@odersky odersky added this to the 3.3.0 backports milestone Jan 17, 2023
@odersky odersky requested a review from dwijnand January 17, 2023 12:45
@odersky odersky merged commit 23febb8 into scala:main Jan 23, 2023
@odersky odersky deleted the fix-16707 branch January 23, 2023 15:26
@Kordyjan Kordyjan modified the milestones: 3.3.0 backports, 3.3.1 Aug 1, 2023
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.

Regression in katrix/perspective (non-reducible Tuple type in match types) Regression in katrix/perspective (stack overflow with match types)

3 participants