Skip to content

Anonymous class lifted in wrong package #3000

Closed
@nicolasstucki

Description

@nicolasstucki
class Foo {
  new Object { }
}

package bar { }

fails Ycheck with

checking Foo.scala after phase TreeTransform:{linkScala2Impls, lambdaLift, elimStaticThis, flatten, restoreScopes}
exception while typing package bar {
  private <static> class $anon extends Object { 
    def <init>(): Unit = 
      {
        super()
        ()
      }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 416
exception while typing package <empty> {
  @scala.annotation.internal.SourceFile("Foo.scala") class Foo extends Object { 
    def <init>(): Unit = 
      {
        super()
        {
          new Object{...}(): Object
        }
        ()
      }
  }
  package bar {
    private <static> class $anon extends Object { 
      def <init>(): Unit = 
        {
          super()
          ()
        }
    }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 417
*** error while checking Foo.scala after phase restoreScopes ***

exception occurred while compiling Foo.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: bad owner; anonymous class Object{...} has owner package <empty>, expected was package bar
owner chain = anonymous class Object{...}, package <empty>, package <root>, ctxOwners = package bar, package <empty>, package <root>, package <root>, package <root>, package <root>, package <root>, package <root>, package <root>, <none>, <none>, <none>, <none>
	at scala.Predef$.assert(Predef.scala:170)
	at dotty.tools.dotc.transform.TreeChecker$Checker.dotty$tools$dotc$transform$TreeChecker$Checker$$checkOwner(TreeChecker.scala:360)
	at dotty.tools.dotc.transform.TreeChecker$Checker$$anonfun$typedStats$1.apply(TreeChecker.scala:429)
	at dotty.tools.dotc.transform.TreeChecker$Checker$$anonfun$typedStats$1.apply(TreeChecker.scala:428)
	at scala.collection.immutable.List.foreach(List.scala:392)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:428)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1517)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1504)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1504)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1657)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1674)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:275)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1689)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1687)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1687)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:260)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1722)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1734)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:433)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1517)
	at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1504)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1504)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1657)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1674)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:94)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:275)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1689)
	at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1687)
	at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
	at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1687)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:260)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1746)
	at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:133)
	at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:105)
	at dotty.tools.dotc.core.Phases$Phase$$anonfun$runOn$1.apply(Phases.scala:283)
	at dotty.tools.dotc.core.Phases$Phase$$anonfun$runOn$1.apply(Phases.scala:281)
	at scala.collection.immutable.List.map(List.scala:284)
	at dotty.tools.dotc.core.Phases$Phase$class.runOn(Phases.scala:281)
	at dotty.tools.dotc.transform.TreeChecker.runOn(TreeChecker.scala:48)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:81)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:78)
	at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply$mcV$sp(Run.scala:78)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:66)
	at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:66)
	at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:66)
	at dotty.tools.dotc.Run.compileSources(Run.scala:63)
	at dotty.tools.dotc.Run.compile(Run.scala:47)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:26)
	at dotty.tools.dotc.Driver.process(Driver.scala:124)
	at dotty.tools.dotc.Driver.process(Driver.scala:93)
	at dotty.tools.dotc.Driver.process(Driver.scala:105)
	at dotty.tools.dotc.Driver.main(Driver.scala:132)
	at dotty.tools.dotc.Main.main(Main.scala)

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