-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Crash in ExplicitOuter involving compiler-generated ordinal method in companion of inner sealed class #10769
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
Comments
Please may you copy the crash stacktrace into the details block? |
@bishabosha sorry yes, done! |
Dotty bug tracked in scala/scala3#10769
We can get it to crash earlier (in the phase group of ExplicitOuter instead of at Erasure) with assertion failed: error while typing Internals$.this, method ordinal is not contained in object Internals
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedThis(TreeChecker.scala:412)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2490)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2551)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$2(ProtoTypes.scala:367)
at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:323)
at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:368)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:825)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:825)
at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:545)
at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:616)
at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:366)
at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:720)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:824)
at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1051)
at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:236)
at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:100)
at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:898)
at dotty.tools.dotc.typer.Applications.realApply$5$$anonfun$4(Applications.scala:977)
at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2748)
at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:988)
at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1026)
at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:236)
at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:100)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2489)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2551)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$2(ProtoTypes.scala:367)
at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:323)
at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:368)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:825)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:825)
at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:545)
at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:616)
at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:366)
at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:720)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:824)
at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1051)
at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:236)
at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:100)
at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:898)
at dotty.tools.dotc.typer.Applications.realApply$5$$anonfun$4(Applications.scala:977)
at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2748)
at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:988)
at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1026)
at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:236)
at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:100)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2489)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2551)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2620)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
at dotty.tools.dotc.typer.Typer.typedIf(Typer.scala:960)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2498)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2551)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2620)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2673)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2696)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:521)
at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:906)
at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:910)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$2$$anonfun$1(TreeChecker.scala:503)
at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:199)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:503)
at dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:227)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:503)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2497)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2551)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2620)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
at dotty.tools.dotc.typer.Typer.typedLabeled(Typer.scala:1483)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedLabeled$$anonfun$1(TreeChecker.scala:526)
at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:199)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedLabeled(TreeChecker.scala:526)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2482)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2550)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2620)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2740)
at dotty.tools.dotc.typer.Typer.$anonfun$33(Typer.scala:1995)
at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:216)
at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1995)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef$$anonfun$2$$anonfun$1(TreeChecker.scala:477)
at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:199)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef$$anonfun$1(TreeChecker.scala:480)
at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:199)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef(TreeChecker.scala:481)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2466)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2550)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2620)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2646)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2696)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:521)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2139)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedClassDef(TreeChecker.scala:453)
at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2477)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2481)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2550)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2620)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2646)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2696)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:521)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2139)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedClassDef(TreeChecker.scala:453)
at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2477)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2481)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2550)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2620)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2646)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2696)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:521)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2274)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedPackageDef(TreeChecker.scala:547)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2522)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2551)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:125)
at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:333)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2620)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:317)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2740)
at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:151)
at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:120)
at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:296)
at scala.collection.immutable.List.map(List.scala:246)
at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:297)
at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:185)
at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
at dotty.tools.dotc.Run.runPhases$5(Run.scala:195)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:203)
at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
at dotty.tools.dotc.Run.compileUnits(Run.scala:210)
at dotty.tools.dotc.Run.compileSources(Run.scala:147)
at dotty.tools.dotc.Run.compile(Run.scala:129)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
at dotty.tools.dotc.Driver.process(Driver.scala:193)
at dotty.tools.dotc.Driver.process(Driver.scala:162)
at dotty.tools.dotc.Driver.process(Driver.scala:174)
at dotty.tools.dotc.Driver.main(Driver.scala:201)
at dotty.tools.dotc.Main.main(Main.scala) |
The generated type MirroredMonoType = STMLike.this.Txn[? <: AnyKind]
def ordinal(x$0: stm.STMLike.Txn.MirroredMonoType): Int =
x$0 match
{
case _:stm.STMLike.Internals.Abort => 0
} If I try to reproduce this in source-code I don't get a crash: package stm
trait STMLike[F[_]] {
import Internals._
/*sealed*/ abstract class Txn[+A] {}
object Txn {
type MirroredMonoType = STMLike.this.Txn[?]
def ordinal(x: Txn.MirroredMonoType): Int =
x match {
case _: Internals.Abort => 0
}
def abort[A](e: Throwable): Txn[A] = Abort(e)
}
object Internals {
case class Abort(error: Throwable) extends Txn[Nothing]
}
} So I suspect the problem is with the exact shape of the types in the generated method (in particular |
Indeed, I think the issue is that for TypeRef(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class stm)),trait STMLike)),module class Internals$)),class Abort) But since we're not inside |
As pointed out by @smarter in scala#10769, for the following code: package stm trait STMLike[F[_]] { import Internals._ sealed abstract class Txn[+A] {} object Txn { def abort[A](e: Throwable): Txn[A] = Abort(e) } object Internals { case class Abort(error: Throwable) extends Txn[Nothing] } } The compiler synthesized the following code for the object `Txn`: object Txn { type MirroredMonoType = STMLike.this.Txn[?] def ordinal(x: Txn.MirroredMonoType): Int = x match { case _:stm.STMLike.Internals.Abort => 0 } def abort[A](e: Throwable): Txn[A] = Abort(e) } In the method `ordinal`, the type for `Internals.Abort` is TypeRef(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class stm)),trait STMLike)),module class Internals$)),class Abort) This type is incorrect, as we are not in the object `Internals`. The explicit outer can only handle such types if it's static. In this case, the object is not static, thus it crashes the explicit outer. Co-authored-by: Guillaume Martres <[email protected]>
As pointed out by @smarter in scala#10769, for the following code: package stm trait STMLike[F[_]] { import Internals._ sealed abstract class Txn[+A] {} object Txn { def abort[A](e: Throwable): Txn[A] = Abort(e) } object Internals { case class Abort(error: Throwable) extends Txn[Nothing] } } The compiler synthesized the following code for the object `Txn`: object Txn { type MirroredMonoType = STMLike.this.Txn[?] def ordinal(x: Txn.MirroredMonoType): Int = x match { case _:stm.STMLike.Internals.Abort => 0 } def abort[A](e: Throwable): Txn[A] = Abort(e) } In the method `ordinal`, the type for `Internals.Abort` is TypeRef(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class stm)),trait STMLike)),module class Internals$)),class Abort) This type is incorrect, as we are not in the object `Internals`. The explicit outer can only handle such types if it's static. In this case, the object is not static, thus it crashes the explicit outer. Co-authored-by: Guillaume Martres <[email protected]>
As pointed out by @smarter in scala#10769, for the following code: package stm trait STMLike[F[_]] { import Internals._ sealed abstract class Txn[+A] {} object Txn { def abort[A](e: Throwable): Txn[A] = Abort(e) } object Internals { case class Abort(error: Throwable) extends Txn[Nothing] } } The compiler synthesized the following code for the object `Txn`: object Txn { type MirroredMonoType = STMLike.this.Txn[?] def ordinal(x: Txn.MirroredMonoType): Int = x match { case _:stm.STMLike.Internals.Abort => 0 } def abort[A](e: Throwable): Txn[A] = Abort(e) } In the method `ordinal`, the type for `Internals.Abort` is TypeRef(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class stm)),trait STMLike)),module class Internals$)),class Abort) This type is incorrect, as we are not in the object `Internals`. The explicit outer can only handle such types if it's static. In this case, the object is not static, thus it crashes the explicit outer. Co-authored-by: Guillaume Martres <[email protected]>
As pointed out by @smarter in scala#10769, for the following code: package stm trait STMLike[F[_]] { import Internals._ sealed abstract class Txn[+A] {} object Txn { def abort[A](e: Throwable): Txn[A] = Abort(e) } object Internals { case class Abort(error: Throwable) extends Txn[Nothing] } } The compiler synthesized the following code for the object `Txn`: object Txn { type MirroredMonoType = STMLike.this.Txn[?] def ordinal(x: Txn.MirroredMonoType): Int = x match { case _:stm.STMLike.Internals.Abort => 0 } def abort[A](e: Throwable): Txn[A] = Abort(e) } In the method `ordinal`, the type for `Internals.Abort` is TypeRef(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class stm)),trait STMLike)),module class Internals$)),class Abort) This type is incorrect, as we are not in the object `Internals`. The explicit outer can only handle such types if it's static. In this case, the object is not static, thus it crashes the explicit outer. Co-authored-by: Guillaume Martres <[email protected]>
As pointed out by @smarter in scala#10769, for the following code: package stm trait STMLike[F[_]] { import Internals._ sealed abstract class Txn[+A] {} object Txn { def abort[A](e: Throwable): Txn[A] = Abort(e) } object Internals { case class Abort(error: Throwable) extends Txn[Nothing] } } The compiler synthesized the following code for the object `Txn`: object Txn { type MirroredMonoType = STMLike.this.Txn[?] def ordinal(x: Txn.MirroredMonoType): Int = x match { case _:stm.STMLike.Internals.Abort => 0 } def abort[A](e: Throwable): Txn[A] = Abort(e) } In the method `ordinal`, the type for `Internals.Abort` is TypeRef(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class stm)),trait STMLike)),module class Internals$)),class Abort) This type is incorrect, as we are not in the object `Internals`. The explicit outer can only handle such types if it's static. In this case, the object is not static, thus it crashes the explicit outer. Co-authored-by: Guillaume Martres <[email protected]>
As pointed out by @smarter in scala#10769, for the following code: package stm trait STMLike[F[_]] { import Internals._ sealed abstract class Txn[+A] {} object Txn { def abort[A](e: Throwable): Txn[A] = Abort(e) } object Internals { case class Abort(error: Throwable) extends Txn[Nothing] } } The compiler synthesized the following code for the object `Txn`: object Txn { type MirroredMonoType = STMLike.this.Txn[?] def ordinal(x: Txn.MirroredMonoType): Int = x match { case _:stm.STMLike.Internals.Abort => 0 } def abort[A](e: Throwable): Txn[A] = Abort(e) } In the method `ordinal`, the type for `Internals.Abort` is TypeRef(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class stm)),trait STMLike)),module class Internals$)),class Abort) This type is incorrect, as we are not in the object `Internals`. The explicit outer can only handle such types if it's static. In this case, the object is not static, thus it crashes the explicit outer. Co-authored-by: Guillaume Martres <[email protected]>
Fix #10769: change synthesized type in def ordinal
Uh oh!
There was an error while loading. Please reload this page.
Minimzed from TimWSpence/cats-stm#196
Minimized code
Output (click arrow to expand)
The text was updated successfully, but these errors were encountered: