Skip to content

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

Closed
TimWSpence opened this issue Dec 13, 2020 · 5 comments · Fixed by #10785

Comments

@TimWSpence
Copy link
Contributor

TimWSpence commented Dec 13, 2020

Minimzed from TimWSpence/cats-stm#196

Minimized 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]
  }

}

Output (click arrow to expand)

-- [E029] Pattern Match Exhaustivity Warning: try/i10769.scala:8:9 -------------
8 |  object Txn {
  |         ^
  |         match may not be exhaustive.
  |
  |         It would fail on pattern case: Internals.Abort(_)

longer explanation available when compiling with `-explain`
exception while typing Internals$.this of class class dotty.tools.dotc.ast.Trees$This # -1
exception while typing x1.$asInstanceOf$[stm.STMLike.Internals.Abort].
  stm$STMLike$Internals$Abort$$$outer
.eq(Internals$.this) of class class dotty.tools.dotc.ast.Trees$Apply # -1
exception while typing x1.$isInstanceOf$[stm.STMLike.Internals.Abort].&&(
  x1.$asInstanceOf$[stm.STMLike.Internals.Abort].
    stm$STMLike$Internals$Abort$$$outer
  .eq(Internals$.this)
) of class class dotty.tools.dotc.ast.Trees$Apply # -1
exception while typing if 
  x1.$isInstanceOf$[stm.STMLike.Internals.Abort].&&(
    x1.$asInstanceOf$[stm.STMLike.Internals.Abort].
      stm$STMLike$Internals$Abort$$$outer
    .eq(Internals$.this)
  )
 then return[matchResult1] 0 else () of class class dotty.tools.dotc.ast.Trees$If # -1
[...]

Exception in thread "main" java.lang.AssertionError: assertion failed: failure to construct path from method ordinal/object Txn/trait STMLike/package stm/package <root> to `this` of object Internals in trait STMLike;
trait STMLike in package stm does not have an outer accessor while compiling try/i10769.scala
java.lang.AssertionError: assertion failed: failure to construct path from method ordinal/object Txn/trait STMLike/package stm/package <root> to `this` of object Internals in trait STMLike;
trait STMLike in package stm does not have an outer accessor
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.loop$1(ExplicitOuter.scala:410)
        at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.path$extension(ExplicitOuter.scala:429)
        at dotty.tools.dotc.transform.Erasure$Typer.typedThis(Erasure.scala:747)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2740)
        at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$4(Erasure.scala:792)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.zipWithConserve$extension(Decorators.scala:149)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:792)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2740)
        at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$4(Erasure.scala:792)
        at dotty.tools.dotc.core.Decorators$ListDecorator$.zipWithConserve$extension(Decorators.scala:149)
        at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:792)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        at dotty.tools.dotc.typer.Typer.typedIf(Typer.scala:960)
        at dotty.tools.dotc.transform.Erasure$Typer.typedIf(Erasure.scala:826)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        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.Erasure$Typer.typedStats(Erasure.scala:984)
        at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:906)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:910)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        at dotty.tools.dotc.typer.Typer.typedLabeled(Typer.scala:1483)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        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.Erasure$Typer.typedDefDef(Erasure.scala:893)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        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.Erasure$Typer.typedStats(Erasure.scala:984)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2139)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        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.Erasure$Typer.typedStats(Erasure.scala:984)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2139)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        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.Erasure$Typer.typedStats(Erasure.scala:984)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2274)
        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.typer.Typer.typed(Typer.scala:2620)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2624)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2740)
        at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:123)
        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)
@bishabosha
Copy link
Member

bishabosha commented Dec 13, 2020

Please may you copy the crash stacktrace into the details block?

@TimWSpence
Copy link
Contributor Author

@bishabosha sorry yes, done!

TimWSpence added a commit to TimWSpence/cats-stm that referenced this issue Dec 13, 2020
Dotty bug tracked in scala/scala3#10769
@smarter smarter changed the title Compiler crash Crash in ExplicitOuter involving compiler-generated ordinal method in companion of inner sealed class Dec 13, 2020
@smarter
Copy link
Member

smarter commented Dec 13, 2020

We can get it to crash earlier (in the phase group of ExplicitOuter instead of at Erasure) with -Ycheck:all:

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)

@smarter
Copy link
Member

smarter commented Dec 13, 2020

The generated ordinal method where the crash happens is:

      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 stm.STMLike.Txn.MirroredMonoType and stm.STMLike.Internals.Abort look suspicious: to select a member from the outer class it should be stm.STMLike.this.Txn.MirroredMonoType and stm.STMLike.this.Internals.Abort, but this might be a pretty-printing artefact).

@smarter
Copy link
Member

smarter commented Dec 13, 2020

So I suspect the problem is with the exact shape of the types in the generated method

Indeed, I think the issue is that for case _:stm.STMLike.Internals.Abort we generate the following type (via patType in ordinalBody):

TypeRef(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class stm)),trait STMLike)),module class Internals$)),class Abort)

But since we're not inside Internals at this point, a ThisType to Internals$ doesn't really make sense.

@liufengyun liufengyun self-assigned this Dec 14, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue Dec 14, 2020
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]>
liufengyun added a commit to dotty-staging/dotty that referenced this issue Dec 14, 2020
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]>
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 6, 2021
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]>
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 6, 2021
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]>
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 6, 2021
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]>
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 6, 2021
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]>
liufengyun added a commit that referenced this issue Jan 7, 2021
Fix #10769: change synthesized type in def ordinal
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

5 participants