-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix check whether classtag can be generated for match types (#16708)
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
- Loading branch information
Showing
6 changed files
with
46 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import scala.deriving.Mirror | ||
import scala.reflect.ClassTag | ||
|
||
type TupleUnionLub[T <: Tuple, Lub, Acc <: Lub] <: Lub = T match { | ||
case (h & Lub) *: t => TupleUnionLub[t, Lub, Acc | h] | ||
case EmptyTuple => Acc | ||
} | ||
|
||
transparent inline given derived[A]( | ||
using m: Mirror.SumOf[A], | ||
idClassTag: ClassTag[TupleUnionLub[m.MirroredElemTypes, A, Nothing]] | ||
): Unit = () | ||
|
||
sealed trait Foo | ||
case class FooA(a: Int) extends Foo | ||
|
||
val instance = derived[Foo] // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import scala.deriving.Mirror | ||
import scala.reflect.ClassTag | ||
|
||
transparent inline given derived[A]( | ||
using m: Mirror.ProductOf[A], | ||
idClassTag: ClassTag[Tuple.Union[m.MirroredElemTypes]] | ||
): Unit = ??? | ||
|
||
case class Foo(a: Int) | ||
|
||
val instance = derived[Foo] // error |