Value class parameterized by subtype of primitive type crashes compiler #10221
Open
Description
Attempting to run this code in the Repl:
implicit class Foo[T <: Long](val a : T) extends AnyVal {
def bar = a + 1
}
Results in:
ReplGlobal.abort: Erasure should have added an unboxing operation to prevent this cast. Tree: $this.$asInstanceOf[Long]()
error:
Erasure should have added an unboxing operation to prevent this cast. Tree: $this.$asInstanceOf[Long]()
while compiling: <console>
during phase: jvm
library version: version 2.12.1
compiler version: version 2.12.1
reconstructed args: -deprecation -feature
last tree to typer: TypeTree(class Long)
tree position: line 11 of <console>
tree tpe: Long
symbol: (final abstract) class Long in package scala
symbol definition: final abstract class Long extends (a ClassSymbol)
symbol package: scala
symbol owners: class Long
call site: constructor $read$Foo in package $line3
<Cannot read source file>
scala.reflect.internal.FatalError:
Erasure should have added an unboxing operation to prevent this cast. Tree: $this.$asInstanceOf[Long]()
while compiling: <console>
during phase: jvm
library version: version 2.12.1
compiler version: version 2.12.1
reconstructed args: -deprecation -feature
last tree to typer: TypeTree(class Long)
tree position: line 11 of <console>
tree tpe: Long
symbol: (final abstract) class Long in package scala
symbol definition: final abstract class Long extends (a ClassSymbol)
symbol package: scala
symbol owners: class Long
call site: constructor $read$$iw$$iw$Foo in package $line3
<Cannot read source file>
at scala.reflect.internal.Reporting.abort(Reporting.scala:61)
at scala.reflect.internal.Reporting.abort$(Reporting.scala:57)
at scala.tools.nsc.interpreter.IMain$$anon$1.scala$tools$nsc$interpreter$ReplGlobal$$super$abort(IMain.scala:242)
at scala.tools.nsc.interpreter.ReplGlobal.abort(ReplGlobal.scala:23)
at scala.tools.nsc.interpreter.ReplGlobal.abort$(ReplGlobal.scala:21)
at scala.tools.nsc.interpreter.IMain$$anon$1.abort(IMain.scala:242)
at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genTypeApply$1(BCodeBodyBuilder.scala:539)
at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:552)
at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:298)
at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genArithmeticOp(BCodeBodyBuilder.scala:129)
at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genPrimitiveOp(BCodeBodyBuilder.scala:218)
at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:653)
at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:298)
at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.emitNormalMethodBody$1(BCodeSkelBuilder.scala:603)
at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genDefDef(BCodeSkelBuilder.scala:635)
at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:509)
at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.$anonfun$gen$7(BCodeSkelBuilder.scala:511)
at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:511)
at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:113)
at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase$Worker1.visit(GenBCode.scala:190)
at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase$Worker1.$anonfun$run$1(GenBCode.scala:139)
at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase$Worker1.run(GenBCode.scala:139)
at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase.buildAndSendToDisk(GenBCode.scala:381)
at scala.tools.nsc.backend.jvm.GenBCode$BCodePhase.run(GenBCode.scala:350)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1418)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1403)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1398)
at scala.tools.nsc.interpreter.IMain.compileSourcesKeepingRun(IMain.scala:430)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:801)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:759)
at scala.tools.nsc.interpreter.IMain$Request.compile$lzycompute(IMain.scala:948)
at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:943)
at scala.tools.nsc.interpreter.IMain.compile(IMain.scala:599)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:588)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:560)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:825)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:684)
at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:402)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:423)
at scala.tools.nsc.interpreter.ILoop.$anonfun$process$1(ILoop.scala:993)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:892)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:75)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:88)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:99)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:104)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
error: Error while emitting <console>
Erasure should have added an unboxing operation to prevent this cast. Tree: $this.$asInstanceOf[Long]()
while compiling: <console>
during phase: jvm
library version: version 2.12.1
compiler version: version 2.12.1
reconstructed args: -deprecation -feature
last tree to typer: TypeTree(class Long)
tree position: line 11 of <console>
tree tpe: Long
symbol: (final abstract) class Long in package scala
symbol definition: final abstract class Long extends (a ClassSymbol)
symbol package: scala
symbol owners: class Long
call site: constructor $read$Foo in package $line3