File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -273,7 +273,19 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
273273 val cls = mirroredType.classSymbol
274274 val useCompanion = cls.useCompanionAsSumMirror
275275
276- if (! mirroredType.termSymbol.isEnumCase && (cls.isGenericSum(if useCompanion then cls.linkedClass else ctx.owner))) then
276+ val isDisjointed = mirroredType match {
277+ case OrType (t1, t2) => TypeComparer .provablyDisjoint(t1, t2)
278+ case _ => false
279+ }
280+
281+ def isSumWithSingleton (t : Type ): Boolean = {
282+ t match {
283+ case OrType (t1, t2) => isSumWithSingleton(t1) || isSumWithSingleton(t2)
284+ case _ => t.termSymbol.isEnumCase
285+ }
286+ }
287+
288+ if (! isDisjointed && ! isSumWithSingleton(mirroredType) && cls.isGenericSum(if useCompanion then cls.linkedClass else ctx.owner)) then
277289 val elemLabels = cls.children.map(c => ConstantType (Constant (c.name.toString)))
278290
279291 def solve (sym : Symbol ): Type = sym match
Original file line number Diff line number Diff line change @@ -6,10 +6,23 @@ enum Color:
66 case Red , Green , Blue
77end Color
88
9+ enum Bar :
10+ case A (i : Int )
11+ case B (b : Boolean )
12+ case C (s : String )
13+
14+ object Singletons {
15+ object A
16+ object B
17+ }
18+
919object Test {
1020
1121 def main (args : Array [String ]): Unit = {
1222 summon[Mirror .ProductOf [Color ]] // error
1323 summon[Mirror .SumOf [Color .Red .type ]] // error
24+ summon[Mirror .SumOf [Color .Red .type | Color .Green .type ]] // error
25+ summon[Mirror .SumOf [Bar .A | Bar .B ]] // error
26+ summon[Mirror .SumOf [Singletons .A .type | Singletons .B .type ]] // error
1427 }
1528}
You can’t perform that action at this time.
0 commit comments