Skip to content

Commit d25fc49

Browse files
committed
Don't generate Mirror.Sum for simple enum cases
1 parent 29f9d33 commit d25fc49

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
273273
val cls = mirroredType.classSymbol
274274
val useCompanion = cls.useCompanionAsSumMirror
275275

276-
if cls.isGenericSum(if useCompanion then cls.linkedClass else ctx.owner) then
276+
if (!mirroredType.termSymbol.isEnumCase && (cls.isGenericSum(if useCompanion then cls.linkedClass else ctx.owner))) then
277277
val elemLabels = cls.children.map(c => ConstantType(Constant(c.name.toString)))
278278

279279
def solve(sym: Symbol): Type = sym match

tests/neg/scala_enum_testing.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.util.NotGiven
2+
import scala.compiletime.*
3+
import scala.deriving.Mirror
4+
5+
enum Color:
6+
case Red, Green, Blue
7+
end Color
8+
9+
object Test {
10+
11+
def main(args: Array[String]): Unit = {
12+
summon[Mirror.ProductOf[Color]] // error
13+
summon[Mirror.SumOf[Color.Red.type]] // error
14+
}
15+
}

tests/run/scala_enum_testing.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.util.NotGiven
2+
import scala.compiletime.*
3+
import scala.deriving.Mirror
4+
5+
enum Color:
6+
case Red, Green, Blue
7+
end Color
8+
9+
object Test {
10+
11+
def main(args: Array[String]): Unit = {
12+
summon[Mirror.Of[Color.Red.type]]
13+
summon[Mirror.Of[Color]]
14+
summon[Mirror.ProductOf[Color.Red.type]]
15+
summon[Mirror.SumOf[Color]]
16+
}
17+
}

0 commit comments

Comments
 (0)