Scala Programming Language
  1. Scala Programming Language
  2. SI-7388

Compiler crashes when class is set to private of non-enclosing scope

    Details

      Description

      The following line of code without `foo` being an enclosing entity leads to a compiler crash, while correctly stating the error in the code.

      Test.scala
      class Test private[foo]()
      
      Test.scala:1: error: foo is not an enclosing class
      class Test private[foo]()
                 ^
      error:
           while compiling: Test.scala
              during phase: typer
           library version: version 2.10.1
          compiler version: version 2.10.1
        reconstructed args:
      
        last tree to typer: term <init>
                    symbol: constructor Test in class Test (flags: <method>)
         symbol definition: def <init><_>
             symbol owners: constructor Test -> class Test -> package <empty>
            context owners: class Test -> package <empty>
      
      == Enclosing template or block ==
      
      Template( // val <local Test>: <notype> in class Test
        "java.lang.Object" // parents
        ValDef(
          private
          "_"
          <tpt>
          <empty>
        )
        DefDef( // def <init><_> in class Test
          <method>
          "<init>"
          []
          List(Nil)
          <tpt>
          Block(
            Apply(
              super."<init>"
              Nil
            )
            ()
          )
        )
      )
      
      uncaught exception during compilation: java.lang.AssertionError
      error: java.lang.AssertionError: assertion failed: <init>
      	at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1210)
      	at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1365)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5282)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630)
      	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2921)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025)
      	at scala.collection.immutable.List.loop$1(List.scala:170)
      	at scala.collection.immutable.List.mapConserve(List.scala:186)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3025)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1914)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1751)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5571)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630)
      	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2921)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025)
      	at scala.collection.immutable.List.loop$1(List.scala:170)
      	at scala.collection.immutable.List.mapConserve(List.scala:186)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3025)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5288)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5575)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5687)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:99)
      	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
      	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      	at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:91)
      	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1582)
      	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1556)
      	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1552)
      	at scala.tools.nsc.Global$Run.compile(Global.scala:1661)
      	at scala.tools.nsc.Driver.doCompile(Driver.scala:33)
      	at scala.tools.nsc.Main$.doCompile(Main.scala:79)
      	at scala.tools.nsc.Driver.process(Driver.scala:54)
      	at scala.tools.nsc.Driver.main(Driver.scala:67)
      	at scala.tools.nsc.Main.main(Main.scala)
      
      Exception in thread "main" java.lang.AssertionError: assertion failed: <init>
      	at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1210)
      	at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1365)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5282)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630)
      	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2921)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025)
      	at scala.collection.immutable.List.loop$1(List.scala:170)
      	at scala.collection.immutable.List.mapConserve(List.scala:186)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3025)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1914)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1751)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5571)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630)
      	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2921)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025)
      	at scala.collection.immutable.List.loop$1(List.scala:170)
      	at scala.collection.immutable.List.mapConserve(List.scala:186)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3025)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5288)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5575)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5687)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:99)
      	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
      	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      	at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:91)
      	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1582)
      	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1556)
      	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1552)
      	at scala.tools.nsc.Global$Run.compile(Global.scala:1661)
      	at scala.tools.nsc.Driver.doCompile(Driver.scala:33)
      	at scala.tools.nsc.Main$.doCompile(Main.scala:79)
      	at scala.tools.nsc.Driver.process(Driver.scala:54)
      	at scala.tools.nsc.Driver.main(Driver.scala:67)
      	at scala.tools.nsc.Main.main(Main.scala)
      

        Activity

        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/2411

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Dario Rexin
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development