Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot use package as value" #5604

Closed
scabug opened this issue Mar 23, 2012 · 10 comments
Closed

"Cannot use package as value" #5604

scabug opened this issue Mar 23, 2012 · 10 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Mar 23, 2012

I've seen this failure so many zillions of times (when recompiling via ant) and finally it is reduced.

% ./build/pack/bin/scalac src/compiler/scala/tools/nsc/interpreter/ReplReporter.scala src/compiler/scala/tools/nsc/interpreter/ReplConfig.scala

Cannot use package as value: interpreter.this
	at scala.Predef$.assert(Predef.scala:161)
	at scala.tools.nsc.Global.assert(Global.scala:176)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:941)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:1150)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:721)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:1150)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:894)
@scabug
Copy link
Author

scabug commented Mar 23, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5604?orig=1
Reporter: @paulp

@scabug
Copy link
Author

scabug commented Mar 27, 2012

@paulp said:
Sorry, I fixed or at least worked around this between when I reported it and now. I'll check in my workaround shortly, but it doesn't count as a fix so I'll leave this open for miguel.

@scabug
Copy link
Author

scabug commented Mar 27, 2012

@paulp said:
See 2b90e85b68 .

@scabug
Copy link
Author

scabug commented Sep 20, 2012

@retronym said:
Here's better look at the original problem.

2.10.x ~/code/scala for f in sandbox/t5604/*.scala; do echo;echo // $f; cat $f; done

// sandbox/t5604/T.scala
package t6504

trait T {
  def foo: Boolean = false
}

// sandbox/t5604/Test.scala
package t6504

object Test {
  def blerg(a: Any): Any = if (foo) blerg(0)
}

// sandbox/t5604/pack.scala
package t6504

object `package` extends T {
}
2.10.x ~/code/scala scala-hash '2b90e85b68~1' -d sandbox/t5604/out.jar sandbox/t5604/*.scala
2.10.x ~/code/scala scala-hash '2b90e85b68~1' -classpath sandbox/t5604/out.jar sandbox/t5604/T*.scala 
error: 
     while compiling:  sandbox/t5604/Test.scala
       current phase:  icode
     library version:  version 2.10.0-20120327-073128-d078b58961
    compiler version:  version 2.10.0-20120327-073128-d078b58961
  reconstructed args:  -classpath sandbox/t5604/out.jar

uncaught exception during compilation: java.lang.AssertionError
error: java.lang.AssertionError: assertion failed: 
     while compiling:  sandbox/t5604/Test.scala
       current phase:  icode
     library version:  version 2.10.0-20120327-073128-d078b58961
    compiler version:  version 2.10.0-20120327-073128-d078b58961
  reconstructed args:  -classpath sandbox/t5604/out.jar

Cannot use package as value: t6504.this
	at scala.Predef$.assert(Predef.scala:161)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:948)


2.10.x ~/code/scala scala-hash '2b90e85b68' -d sandbox/t5604/out.jar sandbox/t5604/*.scala
2.10.x ~/code/scala scala-hash '2b90e85b68' -classpath sandbox/t5604/out.jar sandbox/t5604/T*.scala 
Bug: found package class where package object expected.  Converting.


2.10.x ~/code/scala scala-hash '2.10.x' -d sandbox/t5604/out.jar sandbox/t5604/*.scala
2.10.x ~/code/scala scala-hash '2.10.x' -classpath sandbox/t5604/out.jar sandbox/t5604/T*.scala 

In summary: the bug is triggered by recompiling a trait that is mixed into a package object, without recompiling that package object at the same time. Paul's workaround changed the crash to an error, but that has since disappeared, suggesting the underlying issue might be resolved.

@scabug
Copy link
Author

scabug commented Sep 20, 2012

@retronym said (edited on Sep 20, 2012 10:16:09 PM UTC):
That was optimistic. In fact, since https://github.com/scala/scala/commit/v2.10.0-M4~118#L10L1211, the underlying problem is only logged under -Ydebug.

@scabug
Copy link
Author

scabug commented Sep 20, 2012

@retronym said:
Making a small change to that file, to fully qualify the reference to the reference to the package object member, triggers a nastier problem.

for f in sandbox/t5604/*.scala; do echo;echo // $f; cat $f; done

// sandbox/t5604/T.scala
package t6504

trait T {
  def foo: Boolean = false
}

// sandbox/t5604/Test.scala
package t6504

object Test {
  def blerg(a: Any): Any = if (t6504.foo) blerg(0)
}

// sandbox/t5604/pack.scala
package t6504

object `package` extends T {
}
2.10.x ~/code/scala export hash=2.10.x && (scala-hash "$hash" -version; rm sandbox/t5604/out.jar 2>/dev/null; scala-hash "$hash" -d sandbox/t5604/out.jar sandbox/t5604/*.scala && scala-hash "$hash" -classpath sandbox/t5604/out.jar sandbox/t5604/T*.scala )
Scala compiler version 2.10.0-20120920-130603-c8e6f8e64c -- Copyright 2002-2012, LAMP/EPFL
error: 
     while compiling: sandbox/t5604/Test.scala
        during phase: jvm
     library version: version 2.10.0-20120920-130603-c8e6f8e64c
    compiler version: version 2.10.0-20120920-130603-c8e6f8e64c
  reconstructed args: -classpath sandbox/t5604/out.jar

  last tree to typer: TypeTree(trait T)
              symbol: trait T in package t6504 (flags: <interface> abstract <trait> <lateinterface>)
   symbol definition: abstract trait T extends Object
                 tpe: t6504.T
       symbol owners: trait T -> package t6504
      context owners: object Test -> package t6504

== Enclosing template or block ==

Template( // val <local Test>: <notype> in object Test, tree.tpe=t6504.Test.type
  "java.lang.Object" // parents
  ValDef(
    private
    "_"
    <tpt>
    <empty>
  )
  // 2 statements
  DefDef( // def blerg(a: Object): Object in object Test
    <method> <triedcooking>
    "blerg"
    []
    // 1 parameter list
    ValDef( // a: Object
      <param>
      "a"
      <tpt> // tree.tpe=Object
      <empty>
    )
    <tpt> // tree.tpe=Object
    Block( // tree.tpe=Object
      ValDef( // val _$this: t6504.Test.type
        <synthetic>
        "_$this"
        <tpt> // tree.tpe=t6504.Test.type
        This("Test")class Test extends Object in package t6504, tree.tpe=t6504.Test.type
      )
      LabelDef( // def _blerg(x$1: t6504.Test.type,a: Object): Object, tree.tpe=Object
        // 2 paramss
        "_$this" // val _$this: t6504.Test.type, tree.tpe=t6504.Test.type
        "a" // a: Object, tree.tpe=Object
        If( // tree.tpe=Object
          Apply( // def foo(): Boolean in trait T, tree.tpe=Boolean
            t6504.$asInstanceOf[t6504.T]()."foo" // def foo(): Boolean in trait T, tree.tpe=()Boolean
            Nil
          )
          Apply( // def _blerg(x$1: t6504.Test.type,a: Object): Object, tree.tpe=Object
            "_blerg" // def _blerg(x$1: t6504.Test.type,a: Object): Object, tree.tpe=(x$1: t6504.Test.type, a: Object)Object
            // 2 arguments
            This("Test")class Test extends Object in package t6504, tree.tpe=t6504.Test.type
            Apply( // def box(x: Int): Integer in object Int, tree.tpe=Object
              "scala"."Int"."box" // def box(x: Int): Integer in object Int, tree.tpe=(x: Int)Integer
              0
            )
          )
          "scala"."runtime"."BoxedUnit"."UNIT" // final val UNIT: runtime.BoxedUnit in object BoxedUnit, tree.tpe=runtime.BoxedUnit
        )
      )
    )
  )
  DefDef( // def <init>(): t6504.Test.type in object Test
    <method>
    "<init>"
    []
    List(Nil)
    <tpt> // tree.tpe=t6504.Test.type
    Block( // tree.tpe=Unit
      Apply( // def <init>(): Object in class Object, tree.tpe=Object
        Test.super."<init>" // def <init>(): Object in class Object, tree.tpe=()Object
        Nil
      )
      ()
    )
  )
)

== Expanded type of tree ==

TypeRef(TypeSymbol(abstract trait T extends Object))

uncaught exception during compilation: java.lang.ArrayIndexOutOfBoundsException
error: java.lang.ArrayIndexOutOfBoundsException: -1
	at scala.tools.asm.Frame.merge(Unknown Source)
	at scala.tools.asm.Frame.merge(Unknown Source)
	at scala.tools.asm.MethodWriter.visitMaxs(Unknown Source)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genMethod(GenASM.scala:1638)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genClass(GenASM.scala:1471)
	at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:182)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1574)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1548)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1544)
	at scala.tools.nsc.Global$Run.compile(Global.scala:1654)
	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.ArrayIndexOutOfBoundsException: -1
	at scala.tools.asm.Frame.merge(Unknown Source)
	at scala.tools.asm.Frame.merge(Unknown Source)
	at scala.tools.asm.MethodWriter.visitMaxs(Unknown Source)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genMethod(GenASM.scala:1638)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genClass(GenASM.scala:1471)
	at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:182)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1574)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1548)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1544)
	at scala.tools.nsc.Global$Run.compile(Global.scala:1654)
	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)

@scabug
Copy link
Author

scabug commented Sep 20, 2012

@paulp said:
After I bad run of situations where I thought "I know exactly what to do" and I did not actually know exactly what to do, this time I thought that and I was right.

Just running a test or two.

@scabug
Copy link
Author

scabug commented Sep 21, 2012

@paulp said:
scala/scala#1376

@scabug
Copy link
Author

scabug commented Jan 8, 2013

@adriaanm said:
scala/scala#1383

@scabug
Copy link
Author

scabug commented Jan 23, 2013

@adriaanm said:
fixed for 2.11 in paulp/scala@e6f10b0 -- potential backport pending

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants