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

crash when fetch Mirror of union of invariant class #14823

Closed
bishabosha opened this issue Apr 1, 2022 · 3 comments
Closed

crash when fetch Mirror of union of invariant class #14823

bishabosha opened this issue Apr 1, 2022 · 3 comments

Comments

@bishabosha
Copy link
Member

Compiler version

3.1.2-RC3

Minimized code

sealed abstract class Foo[T]
object Foo {
  case class A[T]() extends Foo[T]
}

def foo = summon[deriving.Mirror.Of[Foo[String] | Foo[String]]]

Output (click arrow to expand)

Exception in thread "main" scala.MatchError: OrType(AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <empty>)),object rs$line$2),class Foo),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class scala)),object Predef),type String))),AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <empty>)),object rs$line$2),class Foo),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class scala)),object Predef),type String)))) (of class dotty.tools.dotc.core.Types$CachedOrType)
	at dotty.tools.dotc.transform.TypeUtils$.companionRef(TypeUtils.scala:91)
	at dotty.tools.dotc.typer.Synthesizer.companionPath(Synthesizer.scala:208)
	at dotty.tools.dotc.typer.Synthesizer.sumMirror(Synthesizer.scala:327)
	at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$6$$anonfun$1$$anonfun$1$$anonfun$1(Synthesizer.scala:352)
	at dotty.tools.dotc.typer.Synthesizer.makeMirror(Synthesizer.scala:338)
	at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$6$$anonfun$1(Synthesizer.scala:352)
	at dotty.tools.dotc.typer.Synthesizer.$init$$$anonfun$7$$anonfun$1(Synthesizer.scala:365)
	at dotty.tools.dotc.typer.Synthesizer.recur$1(Synthesizer.scala:505)
	at dotty.tools.dotc.typer.Synthesizer.tryAll(Synthesizer.scala:510)
	at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:863)
	at dotty.tools.dotc.typer.Implicits.inferImplicitArg$(Implicits.scala:791)
	at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:119)
	at dotty.tools.dotc.typer.Typer.implicitArgs$1(Typer.scala:3428)
	at dotty.tools.dotc.typer.Typer.addImplicitArgs$1(Typer.scala:3464)
	at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$1(Typer.scala:3544)
	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3742)
	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3976)
	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3306)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1473)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1463)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1473)
	at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1710)
	at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:238)
	at dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1710)
	at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1718)
	at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1736)
	at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1737)
	at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1748)
	at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1512)
	at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1519)
	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:778)
	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:914)
	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:806)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:168)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:370)
	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2751)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2776)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2454)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2797)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2801)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2871)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2963)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3013)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2581)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2842)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2872)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2937)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2941)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3057)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:259)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1328)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:270)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:278)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:287)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:226)
	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:167)
	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:178)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:262)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:230)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:162)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:165)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:186)
	at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:174)
	at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:80)
	at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:174)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:165)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:127)
	at dotty.tools.repl.Main$.main(Main.scala:6)
@bishabosha
Copy link
Member Author

relevant code that causes the crash:
https://github.com/lampepfl/dotty/blob/ccd504e851d81039bb7a3970cc147388e2b94680/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala#L208

companionRef should not be called on a union type

@bishabosha
Copy link
Member Author

another example here for an illegitimate product type mirror:

case class Cov[+T]()

class SubA[+T]() extends Cov[T]
class SubB[+T]() extends Cov[T]

val foo = summon[deriving.Mirror.ProductOf[SubA[Int] | SubB[Int]]]

@bishabosha
Copy link
Member Author

fixed by commits from #15006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant