Skip to content

Cannot define $outer accessor explicitly #24125

@prolativ

Description

@prolativ

Compiler version

3.7.3, 3.8.0-RC1-bin-20251002-b7cae74-NIGHTLY

Minimized code

class Outer { class Inner { def $outer = Outer.this } }

Output (click arrow to expand)

Exception in thread "main" java.lang.AssertionError: assertion failed: missing outer accessor in class Inner
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:10)
        at dotty.tools.dotc.transform.ExplicitOuter$.dotty$tools$dotc$transform$ExplicitOuter$$$outerParamAccessor(ExplicitOuter.scala:236)
        at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.loop$1(ExplicitOuter.scala:460)
        at dotty.tools.dotc.transform.ExplicitOuter$OuterOps$.path$extension(ExplicitOuter.scala:469)
        at dotty.tools.dotc.transform.Erasure$Typer.typedThis(Erasure.scala:802)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3690)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3783)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3870)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3875)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3986)
        at dotty.tools.dotc.typer.Typer.$anonfun$67(Typer.scala:3044)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:3044)
        at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:966)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3671)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3782)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3870)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3875)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3897)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3943)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1074)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3346)
        at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1050)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3677)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3681)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3782)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3870)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3875)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3897)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3943)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1074)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3346)
        at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1050)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3677)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3681)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3782)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3870)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3875)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3897)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3943)
        at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1074)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3479)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3723)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3783)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3870)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3875)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3986)
        at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:139)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:386)
        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:327)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:379)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:380)
        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:1327)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:373)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$2(Run.scala:420)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1$$anonfun$adapted$1(Run.scala:420)
        at scala.Function0.apply$mcV$sp(Function0.scala:45)
        at dotty.tools.dotc.Run.showProgress(Run.scala:482)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:420)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:432)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:432)
        at dotty.tools.dotc.Run.compileSources(Run.scala:319)
        at dotty.tools.dotc.Run.compile(Run.scala:304)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:201)
        at dotty.tools.dotc.Driver.process(Driver.scala:169)
        at dotty.tools.dotc.Driver.process(Driver.scala:181)
        at dotty.tools.dotc.Driver.main(Driver.scala:211)
        at dotty.tools.dotc.Main.main(Main.scala)

Scala 2 compiler (tested with 2.13.17) is happy to compile this and simply doesn't generate the synthetic $outer accessor.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions