Skip to content

Commit 74eeebd

Browse files
committed
Use strict classSymbol equality to block bad unions
1 parent d317135 commit 74eeebd

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,11 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
273273
val cls = mirroredType.classSymbol
274274
val useCompanion = cls.useCompanionAsSumMirror
275275

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-
}
276+
def acceptable(tp: Type): Boolean = tp match
277+
case OrType(tp1, tp2) => acceptable(tp1) && acceptable(tp2)
278+
case _ => !tp.termSymbol.isEnumCase && (tp.classSymbol eq cls)
287279

288-
if (!isDisjointed && !isSumWithSingleton(mirroredType) && cls.isGenericSum(if useCompanion then cls.linkedClass else ctx.owner)) then
280+
if acceptable(mirroredType) && cls.isGenericSum(if useCompanion then cls.linkedClass else ctx.owner) then
289281
val elemLabels = cls.children.map(c => ConstantType(Constant(c.name.toString)))
290282

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

0 commit comments

Comments
 (0)