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

Compiler crash when accessing case class on object called "$" #8297

Closed
scabug opened this issue Feb 17, 2014 · 5 comments
Closed

Compiler crash when accessing case class on object called "$" #8297

scabug opened this issue Feb 17, 2014 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Feb 17, 2014

Given dollar.scala:

package dollar

trait One {
  case class Two()
}

object $ extends One

Trying to access the class on the object via the REPL causes it to crash:

$ scalac dollar.scala
$ scala
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import dollar.$
import dollar.$

scala> $.Two()
ReplGlobal.abort: Unknown type: <notype>, <notype> [class scala.reflect.internal.Types$NoType$, class scala.reflect.internal.Types$NoType$] TypeRef? false
error: Unknown type: <notype>, <notype> [class scala.reflect.internal.Types$NoType$, class scala.reflect.internal.Types$NoType$] TypeRef? false
error: uncaught exception during compilation: scala.reflect.internal.FatalError
scala.reflect.internal.FatalError: 
     while compiling: <console>
        during phase: icode
     library version: version 2.10.3
    compiler version: version 2.10.3
  reconstructed args: 

  last tree to typer: Apply(method Two)
              symbol: method Two in object $ (flags: <method> <java> <static> <triedcooking>)
   symbol definition: def Two(): <notype>
                 tpe: <notype>
       symbol owners: method Two -> object $ -> package dollar
      context owners: object iw -> package $line4

== Enclosing template or block ==

Template( // val <local $iw>: <notype>, tree.tpe=type
  "java.lang.Object" // parents
  ValDef(
    private
    "_"
    <tpt>
    <empty>
  )
  DefDef( // def <init>(): type
    <method>
    "<init>"
    []
    List(Nil)
    <tpt> // tree.tpe=type
    Block( // tree.tpe=Unit
      Apply( // def <init>(): Object in class Object, tree.tpe=Object
        $read$$iw.super."<init>" // def <init>(): Object in class Object, tree.tpe=()Object
        Nil
      )
      ()
    )
  )
)

== Expanded type of tree ==

<notype>

Unknown type: <notype>, <notype> [class scala.reflect.internal.Types$NoType$, class scala.reflect.internal.Types$NoType$] TypeRef? false
	at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:49)
	at scala.tools.nsc.Global.abort(Global.scala:254)
	at scala.tools.nsc.interpreter.IMain$$anon$1.scala$tools$nsc$interpreter$ReplGlobal$$super$abort(IMain.scala:265)
	at scala.tools.nsc.interpreter.ReplGlobal$class.abort(ReplGlobal.scala:21)
	at scala.tools.nsc.interpreter.IMain$$anon$1.abort(IMain.scala:265)
	at scala.tools.nsc.backend.icode.TypeKinds$class.toTypeKind(TypeKinds.scala:397)
	at scala.tools.nsc.backend.icode.ICodes.toTypeKind(ICodes.scala:20)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:116)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:72)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:149)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:99)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:72)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:90)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:68)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:64)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:464)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:431)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:431)
	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:431)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:57)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1583)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1557)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1553)
	at scala.tools.nsc.interpreter.IMain.compileSourcesKeepingRun(IMain.scala:428)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:801)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:761)
	at scala.tools.nsc.interpreter.IMain$Request.compile$lzycompute(IMain.scala:936)
	at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:931)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:603)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
	at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:756)
	at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:801)
	at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:713)
	at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:577)
	at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:584)
	at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:587)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:878)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833)
	at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
	at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:833)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

That entry seems to have slain the compiler.  Shall I replay
your session? I can re-run each line except the last one.
[y/n]
@scabug
Copy link
Author

scabug commented Feb 17, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8297?orig=1
Reporter: @puffnfresh
See #6888

@scabug
Copy link
Author

scabug commented Feb 17, 2014

@retronym said:
You were warned:

"The ‘$’ character is reserved for compiler-synthesized identifiers. User programs should not define identifiers which contain ‘$’ characters."

We did try to make a very similar case less crashy in #6888. Not sure if this one will be as easy, though.

@scabug
Copy link
Author

scabug commented Feb 27, 2014

@adriaanm said:
$ is off-limits, sorry

@scabug scabug closed this as completed Feb 27, 2014
@scabug
Copy link
Author

scabug commented Jun 21, 2016

@dwijnand said:
This works in 2.11.8 btw:

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.

scala> :pa
// Entering paste mode (ctrl-D to finish)

trait One {
  case class Two()
}

object $ extends One

// Exiting paste mode, now interpreting.

defined trait One
defined object $

scala> $.Two()
res0: $.Two = Two()

@scabug
Copy link
Author

scabug commented Jun 21, 2016

@dwijnand said:
Well, if I actually do it exactly the way shown it doesn't work, but at least it's not a crash anymore:

15:53:54 $ scalac dollar.scala
15:53:58 $ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.

scala> import dollar.$
import dollar.$

scala> $.Two()
error: Unable to locate class corresponding to inner class entry for Two$ in owner dollar.One

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