Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I report this assertion failure? What is $asInstanceOf anyway?

If you bother the Scala compiler (2.9.1 or 2.10.0-M7) with this really bad snippet of code...

null.$asInstanceOf[Int]

... it throws an assertion failure. Questions: What is $asInstanceOf? Should I report this as a bug?

Here is the stack trace:

java.lang.AssertionError: assertion failed: null.$asInstanceOf[Int]()
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:754)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:850)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1226)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1224)
        at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
        at scala.collection.immutable.List.foldLeft(List.scala:76)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadArguments(GenICode.scala:1224)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:924)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:114)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:76)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:69)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:136)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:88)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:76)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:69)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:79)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:65)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:61)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:329)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
        at scala.collection.Iterator$class.foreach(Iterator.scala:772)
        at scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:318)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:297)
        at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:54)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
        at scala.tools.nsc.Global$Run.compile(Global.scala:1041)
        at xsbt.CachedCompiler0.run(CompilerInterface.scala:90)
        at xsbt.CachedCompiler0.liftedTree1$1(CompilerInterface.scala:72)
        at xsbt.CachedCompiler0.run(CompilerInterface.scala:72)
        at xsbt.CompilerInterface.run(CompilerInterface.scala:26)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:73)
        at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:35)
        at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:29)
        at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply$mcV$sp(AggressiveCompile.scala:71)
        at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:71)
        at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:71)
        at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:101)
        at sbt.compiler.AggressiveCompile$$anonfun$4.compileScala$1(AggressiveCompile.scala:70)
        at sbt.compiler.AggressiveCompile$$anonfun$4.apply(AggressiveCompile.scala:88)
        at sbt.compiler.AggressiveCompile$$anonfun$4.apply(AggressiveCompile.scala:60)
        at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:24)
        at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:22)
        at sbt.inc.Incremental$.cycle(Incremental.scala:39)
        at sbt.inc.Incremental$.compile(Incremental.scala:26)
        at sbt.inc.IncrementalCompile$.apply(Compile.scala:20)
        at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:96)
        at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:44)
        at sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:31)
        at sbt.Compiler$.apply(Compiler.scala:79)
        at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:571)
        at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:571)
        at sbt.Scoped$$anonfun$hf2$1.apply(Structure.scala:578)
        at sbt.Scoped$$anonfun$hf2$1.apply(Structure.scala:578)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:49)
        at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
        at sbt.Scoped$Reduced$$anonfun$combine$1$$anonfun$apply$12.apply(Structure.scala:311)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$5.work(System.scala:71)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:232)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
        at sbt.Execute.work(Execute.scala:238)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:232)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
like image 223
Kim Stebel Avatar asked Feb 03 '26 01:02

Kim Stebel


1 Answers

The problem is related to your inclusion of a dollar $ in the name. From the Scala Language Specification (section 1.1 Identifiers):

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

Although it doesn't say so explicitly, by implication user programs shouldn't use such identifiers either.

I guess that it's a question of judgement regarding just how bad the results should be, when you stray off the reservation and use such a thing, and whether a compiler crash is included in such permissible results.

like image 126
Paul Butcher Avatar answered Feb 04 '26 14:02

Paul Butcher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!