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

fsc crashes every other time on inner Java enums #6613

Closed
scabug opened this issue Nov 5, 2012 · 9 comments
Closed

fsc crashes every other time on inner Java enums #6613

scabug opened this issue Nov 5, 2012 · 9 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Nov 5, 2012

fsc fails with a notype error every other time (first compilation succeeds, next one fails, next succeeds, next fails, etc.) when referring to a public enum declared inside a Java class.

The error can be reproduced with the following code. Breaking.java:

public class Breaking { public enum Broke { SHARD, CHIP } }

Broken.scala:

class Broken() { def broken() = Breaking.Broke.CHIP }

And to demonstrate the problem:

javac Breaking.java; fsc Broken.scala; fsc Broken.scala

or scalac -Xresident with Broken.scala entered twice.

The 20121101 nightly is still broken. MC3 worked. 20120918 breaks on the same code, but has a complaint (again, only on the second try; in -Xresident mode) not present in later builds:

TypeRef(
  TypeSymbol(final sealed abstract class Breaking$Broke extends Enum)
)

how can getCommonSuperclass() do its job if different class symbols get the same bytecode-level internal name: Breaking$Broke
	at scala.tools.nsc.backend.jvm.GenASM$JBuilder.javaName(GenASM.scala:613)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genConstant(GenASM.scala:1761)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.scala$tools$nsc$backend$jvm$GenASM$JPlainBuilder$$genInstr$1(GenASM.scala:2469)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$$anonfun$genBlock$1$2.apply(GenASM.scala:2402)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$$anonfun$genBlock$1$2.apply(GenASM.scala:2388)
	at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:105)
	at scala.tools.nsc.backend.icode.BasicBlocks$BasicBlock.foreach(BasicBlocks.scala:197)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genBlock$1(GenASM.scala:2388)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genBlocks$1(GenASM.scala:2319)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genCode(GenASM.scala:2932)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genMethod(GenASM.scala:1639)
	at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genClass(GenASM.scala:1474)
	at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:182)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1572)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1546)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1542)
	at scala.tools.nsc.Global$Run.compile(Global.scala:1652)
	at scala.tools.nsc.Main$$anonfun$resident$1.apply(Main.scala:27)
	at scala.tools.nsc.Main$$anonfun$resident$1.apply(Main.scala:23)
	at scala.tools.nsc.EvalLoop$class.inner$1(EvalLoop.scala:19)
	at scala.tools.nsc.EvalLoop$class.loop(EvalLoop.scala:23)
	at scala.tools.nsc.Main$.resident(Main.scala:23)
	at scala.tools.nsc.Main$.doCompile(Main.scala:78)
	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)

Not sure if this is related to the reflection bug on enums (this one), but this one is more serious as it randomly cripples builds if fsc is used.

@scabug
Copy link
Author

scabug commented Nov 5, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6613?orig=1
Reporter: @Ichoran
Affected Versions: 2.10.0-RC1

@scabug
Copy link
Author

scabug commented Jan 22, 2013

jhodkinson said (edited by @JamesIry on Feb 1, 2013 6:00:13 AM UTC):
The unpredicable nature of this bug is annoying. For me, it failed from the command line and in IntelliJ, then suddenly started building fine for a number of times, then after a clean started failing again...

Here's my output:

  last tree to typer: Literal(Constant(com.aa.bb.cc.xjc.XJCRuntimeCompiler))
              symbol: null
   symbol definition: null
                 tpe: Class(classOf[com.aa.bb.cc.xjc.XJCRuntimeCompiler])
       symbol owners:
      context owners: class XJCRuntimeCompiler$LoggerErrorReceiverImpl -> package xjc

== Enclosing template or block ==

Template( // val <local LoggerErrorReceiverImpl>: <notype> in class XJCRuntimeCompiler$LoggerErrorReceiverImpl, tree.tpe=com.aa.bb.cc.xjc.XJCRuntimeCompiler$LoggerErrorReceiverImpl
  "com.sun.tools.xjc.ErrorReceiver" // parents
  ValDef(
    private
    "_"
    <tpt>
    <empty>
  )
  // 5 statements
  DefDef( // def error(ex: org.xml.sax.SAXParseException): Unit in class XJCRuntimeCompiler$LoggerErrorReceiverImpl
    <method>
    "error"
    []
    // 1 parameter list
    ValDef( // ex: org.xml.sax.SAXParseException
      <param> <triedcooking>
      "ex"
      <tpt> // tree.tpe=org.xml.sax.SAXParseException
      <empty>
    )
    <tpt> // tree.tpe=Unit
    Apply( // def warn(x$1: String,x$2: Throwable): Unit in trait Logger, tree.tpe=Unit
      XJCRuntimeCompiler.this.logger()."warn" // def warn(x$1: String,x$2: Throwable): Unit in trait Logger, tree.tpe=(x$1: String, x$2: Throwable)Unit
      // 2 arguments
      "Compile error "
      "ex" // ex: org.xml.sax.SAXParseException, tree.tpe=org.xml.sax.SAXParseException
    )
  )
  DefDef( // def fatalError(ex: org.xml.sax.SAXParseException): Unit in class XJCRuntimeCompiler$LoggerErrorReceiverImpl
    <method>
    "fatalError"
    []
    // 1 parameter list
    ValDef( // ex: org.xml.sax.SAXParseException
      <param> <triedcooking>
      "ex"
      <tpt> // tree.tpe=org.xml.sax.SAXParseException
      <empty>
    )
    <tpt> // tree.tpe=Unit
    Apply( // def warn(x$1: String,x$2: Throwable): Unit in trait Logger, tree.tpe=Unit
      XJCRuntimeCompiler.this.logger()."warn" // def warn(x$1: String,x$2: Throwable): Unit in trait Logger, tree.tpe=(x$1: String, x$2: Throwable)Unit
      // 2 arguments
      "Compile fatal "
      "ex" // ex: org.xml.sax.SAXParseException, tree.tpe=org.xml.sax.SAXParseException
    )
  )
  DefDef( // def warning(ex: org.xml.sax.SAXParseException): Unit in class XJCRuntimeCompiler$LoggerErrorReceiverImpl
    <method>
    "warning"
    []
    // 1 parameter list
    ValDef( // ex: org.xml.sax.SAXParseException
      <param> <triedcooking>
      "ex"
      <tpt> // tree.tpe=org.xml.sax.SAXParseException
      <empty>
    )
    <tpt> // tree.tpe=Unit
    Apply( // def warn(x$1: String,x$2: Throwable): Unit in trait Logger, tree.tpe=Unit
      XJCRuntimeCompiler.this.logger()."warn" // def warn(x$1: String,x$2: Throwable): Unit in trait Logger, tree.tpe=(x$1: String, x$2: Throwable)Unit
      // 2 arguments
      "Compile warning "
      "ex" // ex: org.xml.sax.SAXParseException, tree.tpe=org.xml.sax.SAXParseException
    )
  )
  DefDef( // def info(ex: org.xml.sax.SAXParseException): Unit in class XJCRuntimeCompiler$LoggerErrorReceiverImpl
    <method>
    "info"
    []
    // 1 parameter list
    ValDef( // ex: org.xml.sax.SAXParseException
      <param> <triedcooking>
      "ex"
      <tpt> // tree.tpe=org.xml.sax.SAXParseException
      <empty>
    )
    <tpt> // tree.tpe=Unit
    Apply( // def warn(x$1: String,x$2: Throwable): Unit in trait Logger, tree.tpe=Unit
      XJCRuntimeCompiler.this.logger()."warn" // def warn(x$1: String,x$2: Throwable): Unit in trait Logger, tree.tpe=(x$1: String, x$2: Throwable)Unit
      // 2 arguments
      "Compile info "
      "ex" // ex: org.xml.sax.SAXParseException, tree.tpe=org.xml.sax.SAXParseException
    )
  )
  DefDef( // def <init>(): com.aa.bb.cc.xjc.XJCRuntimeCompiler$LoggerErrorReceiverImpl in class XJCRuntimeCompiler$LoggerErrorReceiverImpl
    <method> <triedcooking>
    "<init>"
    []
    List(Nil)
    <tpt> // tree.tpe=com.aa.bb.cc.xjc.XJCRuntimeCompiler$LoggerErrorReceiverImpl
    Block( // tree.tpe=Unit
      Apply( // def <init>(): com.sun.tools.xjc.ErrorReceiver in class ErrorReceiver, tree.tpe=com.sun.tools.xjc.ErrorReceiver
        XJCRuntimeCompiler$LoggerErrorReceiverImpl.super."<init>" // def <init>(): com.sun.tools.xjc.ErrorReceiver in class ErrorReceiver, tree.tpe=()
com.sun.tools.xjc.ErrorReceiver
        Nil
      )
      ()
    )
  )
)

== Expanded type of tree ==

ConstantType(
  value = Constant(com.aa.bb.cc.xjc.XJCRuntimeCompiler)
)

how can getCommonSuperclass() do its job if different class symbols get the same bytecode-level internal name: scala/Enumeration$Value); see the error output for details.

@scabug
Copy link
Author

scabug commented Jan 31, 2013

@JamesIry said:
Possibly a distant cousin of #6782, except without inline being involved.

@scabug
Copy link
Author

scabug commented Feb 1, 2013

@JamesIry said:
fsc -Xprint:all -Xprint-types Test.scala

On either path we get to this point

[[syntax trees at end of              constructors]] // Test.scala
package <empty>{type} {
  class test extends Object {
    def foo(): Unit = {
      val x: Broke.Breakage = CHIP{Broke.Breakage(CHIP)};
      (){Unit}
    }{Unit};
  }
}

Then, when it works we get

[[syntax trees at end of                   flatten]] // Test.scala
package <empty>{type} {
  class test extends Object {
    def foo(): Unit = {
      val x: Broke$Breakage = CHIP{Broke$Breakage(CHIP)};
      (){Unit}
    }{Unit};
  }
}

However, when it doesn't work we get

[[syntax trees at end of                   flatten]] // Test.scala
package <empty>{type} {
  class test extends Object {
    def foo(): Unit = {
      val x: Broke$Breakage = CHIP{<notype>(CHIP)};
      (){Unit}
    }{Unit};
  }
}

@scabug
Copy link
Author

scabug commented Oct 7, 2013

@retronym said:
Here's a highly symptomatic fix: https://github.com/retronym/scala/compare/ticket;6613?expand=1

@scabug
Copy link
Author

scabug commented Jul 30, 2014

@paulp said:
It also crashes the repl (every other time), it isn't just fsc.

scala
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_11).
Type in expressions to have them evaluated.
Type :help for more information.

scala> J.Broke.SHARD
res0: J.Broke = SHARD

scala> J.Broke.SHARD
ReplGlobal.abort: Unknown type: <notype>(SHARD), <notype> [class scala.reflect.internal.Types$UniqueConstantType, class scala.reflect.internal.Types$NoType$] TypeRef? false
error: Unknown type: <notype>(SHARD), <notype> [class scala.reflect.internal.Types$UniqueConstantType, class scala.reflect.internal.Types$NoType$] TypeRef? false
scala.reflect.internal.FatalError: Unknown type: <notype>(SHARD), <notype> [class scala.reflect.internal.Types$UniqueConstantType, class scala.reflect.internal.Types$NoType$] TypeRef? false
	at scala.reflect.internal.Reporting$class.abort(Reporting.scala:59)
	at scala.tools.nsc.interpreter.IMain$$anon$1.scala$tools$nsc$interpreter$ReplGlobal$$super$abort(IMain.scala:237)
	at scala.tools.nsc.interpreter.ReplGlobal$class.abort(ReplGlobal.scala:20)
	at scala.tools.nsc.interpreter.IMain$$anon$1.abort(IMain.scala:237)
	at scala.tools.nsc.backend.icode.TypeKinds$class.toTypeKind(TypeKinds.scala:401)
	at scala.tools.nsc.backend.icode.ICodes.toTypeKind(ICodes.scala:19)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadLiteral$1(GenICode.scala:907)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:911)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase

@scabug
Copy link
Author

scabug commented Oct 9, 2014

@scabug
Copy link
Author

scabug commented Jun 25, 2015

@lrytz said:
test/files/res/t6613.res crashes GenBCode

@scabug
Copy link
Author

scabug commented Jun 25, 2015

@lrytz said:
GenBCode fix in scala/scala#4580

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

No branches or pull requests

2 participants