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

Compiler crash for a package object containing a class and companion

    Details

      Description

      When I compile the following compilation unit, the compiler crashes upon the third compilation. I do not delete the generated class files between the compiler runs.

      package p {
        package object base {
          case class B()
        }
      }
      

      The first compiler run is fine, the second generates a message regarding a suppressed failed assert, and on the third run the compiler crashes.

      % scalac -version
      Scala compiler version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
      
      % rm -r p
      % scalac Test.scala
      % scalac Test.scala
      Suppressing failed assert: java.lang.AssertionError: assertion failed: List(obje
      ct package$B, object package$B)
      
      % scalac Test.scala
      Suppressing failed assert: java.lang.AssertionError: assertion failed: List(obje
      ct package$B, object package$B)
      error: java.lang.AssertionError: assertion failed: List(object package$B, object
       package$B)
              at scala.tools.nsc.symtab.Symbols$Symbol.suchThat(Symbols.scala:1055)
              at scala.tools.nsc.symtab.Symbols$Symbol.companionModule0(Symbols.scala:
      1317)
              at scala.tools.nsc.symtab.Symbols$Symbol.companionSymbol(Symbols.scala:1
      338)
              at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.scalaSignatureAd
      dingMarker(GenJVM.scala:236)
              at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.
      scala:350)
              at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJ
      VM.scala:86)
              at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJ
      VM.scala:86)
              at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(Has
      hMap.scala:104)
              at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(Has
      hMap.scala:104)
              at scala.collection.Iterator$class.foreach(Iterator.scala:772)
              at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:15
      7)
              at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala
      :190)
              at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:45)
              at scala.collection.mutable.HashMap$$anon$2.foreach(HashMap.scala:104)
              at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:86)
              at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
              at scala.tools.nsc.Global$Run.compile(Global.scala:1041)
              at scala.tools.nsc.Main$.process(Main.scala:106)
              at scala.tools.nsc.Main$.main(Main.scala:123)
              at scala.tools.nsc.Main.main(Main.scala)
      
      Exception in thread "main" java.lang.AssertionError: assertion failed: List(obje
      ct package$B, object package$B)
              at scala.tools.nsc.symtab.Symbols$Symbol.suchThat(Symbols.scala:1055)
              at scala.tools.nsc.symtab.Symbols$Symbol.companionModule0(Symbols.scala:
      1317)
              at scala.tools.nsc.symtab.Symbols$Symbol.companionSymbol(Symbols.scala:1
      338)
              at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.scalaSignatureAd
      dingMarker(GenJVM.scala:236)
              at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.
      scala:350)
              at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJ
      VM.scala:86)
              at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJ
      VM.scala:86)
              at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(Has
      hMap.scala:104)
              at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(Has
      hMap.scala:104)
              at scala.collection.Iterator$class.foreach(Iterator.scala:772)
              at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:15
      7)
              at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala
      :190)
              at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:45)
              at scala.collection.mutable.HashMap$$anon$2.foreach(HashMap.scala:104)
              at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:86)
              at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
              at scala.tools.nsc.Global$Run.compile(Global.scala:1041)
              at scala.tools.nsc.Main$.process(Main.scala:106)
              at scala.tools.nsc.Main$.main(Main.scala:123)
              at scala.tools.nsc.Main.main(Main.scala)
      
      

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          "I think Rex Kerr has a point when he says that we should be able to suppress warnings (especially new ones):"

          This guy probably has a point as well.

          SI-1781

          Show
          Paul Phillips added a comment - "I think Rex Kerr has a point when he says that we should be able to suppress warnings (especially new ones):" This guy probably has a point as well. SI-1781
          Hide
          Adriaan Moors added a comment -

          Scheduling for 2.10.1-RC3 because we should make the warning less intrusive in 2.10

          Show
          Adriaan Moors added a comment - Scheduling for 2.10.1-RC3 because we should make the warning less intrusive in 2.10
          Hide
          James Iry added a comment -

          Paul and I have both spent some time working on this. It's extremely unlikely that the fix for this bug will be low-risk enough to be applicable to an RC. Plus, the bug has existed since 2.9 so it doesn't qualify as a 2.10.1 regression that could go into an RC.

          I'm de-scheduling this one from RC3 and opening another ticket for suppressing the new warnings. If Paul (or whoever) discovers that the fix for this bug is low enough risk after all (and binary compatible) then we can schedule a back-port to 2.10.x and eliminate the warning entirely.

          Show
          James Iry added a comment - Paul and I have both spent some time working on this. It's extremely unlikely that the fix for this bug will be low-risk enough to be applicable to an RC. Plus, the bug has existed since 2.9 so it doesn't qualify as a 2.10.1 regression that could go into an RC. I'm de-scheduling this one from RC3 and opening another ticket for suppressing the new warnings. If Paul (or whoever) discovers that the fix for this bug is low enough risk after all (and binary compatible) then we can schedule a back-port to 2.10.x and eliminate the warning entirely.
          Hide
          Jason Zaugg added a comment -

          Throw in implicit classes for a first-time crash:

          package p1 {
            object `package` {
              implicit class Foo(a: Any)
              object Foo
            }
          }
          
          scalac-hash v2.11.0-M5 sandbox/test1.scala
          [info] v2.11.0-M5 => /Users/jason/usr/scala-v2.11.0-M5-0-gd6fe890
          sandbox/test1.scala:4: warning: object Foo should be placed directly in package p1 instead of package object p1. Under some circumstances companion objects and case classes in package objects can fail to recompile. See https://issues.scala-lang.org/browse/SI-5954.
              object Foo
                     ^
          sandbox/test1.scala:3: warning: class Foo should be placed directly in package p1 instead of package object p1. Under some circumstances companion objects and case classes in package objects can fail to recompile. See https://issues.scala-lang.org/browse/SI-5954.
              implicit class Foo(a: Any)
                             ^
          error: java.lang.AssertionError: assertion failed: List(object package$Foo, object package$Foo)
          	at scala.reflect.internal.Symbols$Symbol.suchThat(Symbols.scala:1790)
          	at scala.reflect.internal.Symbols$ClassSymbol.companionModule0(Symbols.scala:3089)
          
          Show
          Jason Zaugg added a comment - Throw in implicit classes for a first-time crash: package p1 { object `package` { implicit class Foo(a: Any) object Foo } } scalac-hash v2.11.0-M5 sandbox/test1.scala [info] v2.11.0-M5 => /Users/jason/usr/scala-v2.11.0-M5-0-gd6fe890 sandbox/test1.scala:4: warning: object Foo should be placed directly in package p1 instead of package object p1. Under some circumstances companion objects and case classes in package objects can fail to recompile. See https://issues.scala-lang.org/browse/SI-5954. object Foo ^ sandbox/test1.scala:3: warning: class Foo should be placed directly in package p1 instead of package object p1. Under some circumstances companion objects and case classes in package objects can fail to recompile. See https://issues.scala-lang.org/browse/SI-5954. implicit class Foo(a: Any) ^ error: java.lang.AssertionError: assertion failed: List(object package$Foo, object package$Foo) at scala.reflect.internal.Symbols$Symbol.suchThat(Symbols.scala:1790) at scala.reflect.internal.Symbols$ClassSymbol.companionModule0(Symbols.scala:3089)
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/3389

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Dominik Gruntz
            • Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development