Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't generate Mirror.Sum for simple enum cases #14525

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use strict classSymbol equality to block bad unions
  • Loading branch information
dwijnand committed Mar 9, 2022
commit 74eeebd970a732e63241af04317527893f819c8b
16 changes: 4 additions & 12 deletions compiler/src/dotty/tools/dotc/typer/Synthesizer.scala
Original file line number Diff line number Diff line change
@@ -273,19 +273,11 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
val cls = mirroredType.classSymbol
val useCompanion = cls.useCompanionAsSumMirror

val isDisjointed = mirroredType match {
case OrType(t1, t2) => TypeComparer.provablyDisjoint(t1, t2)
case _ => false
}

def isSumWithSingleton(t: Type): Boolean = {
t match {
case OrType(t1, t2) => isSumWithSingleton(t1) || isSumWithSingleton(t2)
case _ => t.termSymbol.isEnumCase
}
}
def acceptable(tp: Type): Boolean = tp match
bishabosha marked this conversation as resolved.
Show resolved Hide resolved
case OrType(tp1, tp2) => acceptable(tp1) && acceptable(tp2)
case _ => !tp.termSymbol.isEnumCase && (tp.classSymbol eq cls)

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

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