Skip to content

Exception when creating accessors of private fields for inlining #3129

Closed
@OlivierBlanvillain

Description

@OlivierBlanvillain

Two minimized test cases that result in exceptions only when compiled with the inline annotation:

object companions2 {
  inline def foo() = {
    class C {
      println(C.p)
    }

    object C {
      private val p = 1
    }
  }
}
Stacktrace
Exception in thread "main" scala.MatchError: ClassInfo(NoPrefix, module class C$) (of class dotty.tools.dotc.core.Types$CachedClassInfo)
        at dotty.tools.dotc.core.Types$TypeLambdaCompanion.toPInfo(Types.scala:2777)
        at dotty.tools.dotc.core.Types$TypeLambdaCompanion.toPInfo(Types.scala:2773)
        at dotty.tools.dotc.core.Types$LambdaTypeCompanion.$anonfun$fromParams$3(Types.scala:2763)
        at scala.collection.immutable.List.map(List.scala:283)
        at dotty.tools.dotc.core.Types$LambdaTypeCompanion.$anonfun$fromParams$2(Types.scala:2763)
        at dotty.tools.dotc.core.Types$PolyType.(Types.scala:2911)
        at dotty.tools.dotc.core.Types$PolyType$.apply(Types.scala:2979)
        at dotty.tools.dotc.core.Types$PolyType$.apply(Types.scala:2975)
        at dotty.tools.dotc.core.Types$LambdaTypeCompanion.fromParams(Types.scala:2762)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.abstractQualType$1(Inliner.scala:123)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.addAccessor(Inliner.scala:126)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.transform(Inliner.scala:151)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.$anonfun$transform$2(Trees.scala:1215)
        at scala.collection.immutable.List.mapConserve(List.scala:176)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1215)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1128)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.transform(Inliner.scala:142)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.$anonfun$transform$2(Trees.scala:1215)
        at scala.collection.immutable.List.mapConserve(List.scala:176)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1215)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1213)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1197)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.transform(Inliner.scala:142)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1195)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.transform(Inliner.scala:142)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.$anonfun$transform$2(Trees.scala:1215)
        at scala.collection.immutable.List.mapConserve(List.scala:176)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1215)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1213)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1142)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.transform(Inliner.scala:142)
        at dotty.tools.dotc.typer.Inliner$.makeInlineable(Inliner.scala:177)
        at dotty.tools.dotc.typer.Inliner$.$anonfun$registerInlineInfo$1(Inliner.scala:200)
        at dotty.tools.dotc.core.Annotations$LazyBodyAnnotation.tree(Annotations.scala:71)
        at dotty.tools.dotc.typer.Inliner$.bodyAndAccessors(Inliner.scala:213)
        at dotty.tools.dotc.typer.Inliner$.bodyToInline(Inliner.scala:222)
        at dotty.tools.dotc.typer.Typer.inlineExpansion(Typer.scala:1741)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1712)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1733)
        at dotty.tools.dotc.typer.Typer.$anonfun$typedClassDef$1(Typer.scala:1399)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1329)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1617)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1672)
        at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1688)
        at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
        at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1686)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1710)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1733)
        at dotty.tools.dotc.typer.Typer.$anonfun$typedPackageDef$1(Typer.scala:1516)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1503)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1656)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1673)
        at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1688)
        at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
        at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1686)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1745)
        at dotty.tools.dotc.typer.FrontEnd.$anonfun$typeCheck$1(FrontEnd.scala:64)
        at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:62)
        at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$5(FrontEnd.scala:93)
        at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$5$adapted(FrontEnd.scala:93)
        at scala.collection.immutable.List.foreach(List.scala:389)
        at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$2(Run.scala:123)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$2$adapted(Run.scala:120)
        at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
        at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:191)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$1(Run.scala:120)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:108)
        at dotty.tools.dotc.Run.compileSources(Run.scala:95)
        at dotty.tools.dotc.Run.compile(Run.scala:79)
        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)
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
        at scala.sys.package$.error(package.scala:27)
  

class A {
  val b = new B

  class B {
    private inline def getAncestor(p: A): A = {
      p.b.getAncestor(p)
    }
  }
}
Stacktrace
Exception in thread "main" java.lang.AssertionError: assertion failed: isType called on not-a-Type val p
        at scala.Predef$.assert(Predef.scala:219)
        at dotty.tools.dotc.core.Symbols$Symbol.asType(Symbols.scala:434)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.$anonfun$addAccessor$5(Inliner.scala:123)
        at scala.collection.immutable.List.map(List.scala:283)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.abstractQualType$1(Inliner.scala:123)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.addAccessor(Inliner.scala:126)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.transform(Inliner.scala:151)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1142)
        at dotty.tools.dotc.typer.Inliner$addAccessors$2$.transform(Inliner.scala:142)
        at dotty.tools.dotc.typer.Inliner$.makeInlineable(Inliner.scala:177)
        at dotty.tools.dotc.typer.Inliner$.$anonfun$registerInlineInfo$1(Inliner.scala:200)
        at dotty.tools.dotc.core.Annotations$LazyBodyAnnotation.tree(Annotations.scala:71)
        at dotty.tools.dotc.typer.Inliner$.bodyAndAccessors(Inliner.scala:213)
        at dotty.tools.dotc.typer.Inliner$.bodyToInline(Inliner.scala:222)
        at dotty.tools.dotc.typer.Typer.inlineExpansion(Typer.scala:1741)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1712)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1733)
        at dotty.tools.dotc.typer.Typer.$anonfun$typedClassDef$1(Typer.scala:1399)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1329)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1617)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1672)
        at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1688)
        at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
        at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1686)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1710)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1733)
        at dotty.tools.dotc.typer.Typer.$anonfun$typedClassDef$1(Typer.scala:1399)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1329)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1617)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1672)
        at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1688)
        at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
        at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1686)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1710)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1733)
        at dotty.tools.dotc.typer.Typer.$anonfun$typedPackageDef$1(Typer.scala:1516)
        at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1503)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1656)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1673)
        at dotty.tools.dotc.typer.Typer.$anonfun$typed$2(Typer.scala:1688)
        at dotty.tools.dotc.reporting.Reporting.traceIndented(Reporter.scala:140)
        at dotty.tools.dotc.reporting.Reporting.traceIndented$(Reporter.scala:139)
        at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1686)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1745)
        at dotty.tools.dotc.typer.FrontEnd.$anonfun$typeCheck$1(FrontEnd.scala:64)
        at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
        at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:62)
        at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$5(FrontEnd.scala:93)
        at dotty.tools.dotc.typer.FrontEnd.$anonfun$runOn$5$adapted(FrontEnd.scala:93)
        at scala.collection.immutable.List.foreach(List.scala:389)
        at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$2(Run.scala:123)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$2$adapted(Run.scala:120)
        at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
        at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:191)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$1(Run.scala:120)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:108)
        at dotty.tools.dotc.Run.compileSources(Run.scala:95)
        at dotty.tools.dotc.Run.compile(Run.scala:79)
        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)

Both examples blow up in this call, which makes me think that they are related.

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