Skip to content

RuntimeError in backend / erasure #5006

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

Closed
sir-wabbit opened this issue Aug 24, 2018 · 9 comments
Closed

RuntimeError in backend / erasure #5006

sir-wabbit opened this issue Aug 24, 2018 · 9 comments

Comments

@sir-wabbit
Copy link

sir-wabbit commented Aug 24, 2018

object i0 {
  // Adding anything in front of asInstanceOf,
  // i0 or this, makes the error go away.
  def i1: Int = asInstanceOf[Int].toInt
}
Erasure should have added an unboxing operation to prevent this cast. Tree: TypeApply(Ident(asInstanceOf),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)]))
exception occurred while compiling RE-96bd93de803119f21ab5d429b0ce0793869d86c5.scala
Exception in thread "main" java.lang.RuntimeException: Erasure should have added an unboxing operation to prevent this cast. Tree: TypeApply(Ident(asInstanceOf),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)]))
	at dotty.tools.backend.jvm.DottyBackendInterface.abort(DottyBackendInterface.scala:394)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genTypeApply(BCodeBodyBuilder.scala:599)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:428)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:268)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genPrimitiveOp(BCodeBodyBuilder.scala:257)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:711)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:337)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.emitNormalMethodBody$1(BCodeSkelBuilder.scala:602)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genDefDef(BCodeSkelBuilder.scala:635)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:506)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen$$anonfun$1(BCodeSkelBuilder.scala:508)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:508)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:116)
	at dotty.tools.backend.jvm.GenBCodePipeline$Worker1.visit(GenBCode.scala:213)
	at dotty.tools.backend.jvm.GenBCodePipeline$Worker1.run(GenBCode.scala:179)
	at dotty.tools.backend.jvm.GenBCodePipeline.buildAndSendToDisk(GenBCode.scala:419)
	at dotty.tools.backend.jvm.GenBCodePipeline.run(GenBCode.scala:385)
	at dotty.tools.backend.jvm.GenBCode.run(GenBCode.scala:53)

RE-96bd93de803119f21ab5d429b0ce0793869d86c5

@sir-wabbit
Copy link
Author

sir-wabbit commented Aug 24, 2018

I am using a slightly modified Dotty:

diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools
index 606c820..fe441d2 100644
--- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
+++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
@@ -505,7 +505,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
     import scala.tools.asm.util.CheckClassAdapter
     def wrap(body: => Unit): Boolean =
       try { body; true }
-      catch { case ex: Throwable => println(ex.getMessage); false }
+      catch { case ex: Throwable => println(ex.getMessage); throw ex; false }
 
     val valid = wrap {
       if (sym.is(Flags.Method)) {
diff --git a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala b/compiler/src/dotty/tools/backend/jvm/
index ffae0c2..d7a2cba 100644
--- a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala
+++ b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala
@@ -181,6 +181,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
               case ex: Throwable =>
                 ex.printStackTrace()
                 ctx.error(s"Error while emitting ${int.sourceFileFor(item.cunit)}\n${ex.getMessage}")
+                throw ex
             }
           }
         }
@@ -323,6 +324,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
               case ex: Throwable =>
                 ex.printStackTrace()
                 ctx.error(s"Error while emitting ${item.plain.classNode.name}\n${ex.getMessage}")
+                throw ex
             }
           }
         }

but this should not affect the error, only the reporting.

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Aug 26, 2018

Reminds me of #3539 / #4958, which sadly have no link to when they were fixed.

@Blaisorblade
Copy link
Contributor

BTW I suspect we should accept/write such patches under a -Y option, similar to -Yshow-suppressed-errors and -Yno-decode-stacktraces (advocated by @smarter).

@sir-wabbit
Copy link
Author

sir-wabbit commented Aug 26, 2018

The same bug, but a slightly different callstack:

object i0 {
  val i1 = asInstanceOf[Int]
}
Error while emitting RE-d341ba7adb385e80fb9955ca9161dd8f86ad3584.scala
Erasure should have added an unboxing operation to prevent this cast. Tree: TypeApply(Ident(asInstanceOf),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)]))
exception occurred while compiling RE-d341ba7adb385e80fb9955ca9161dd8f86ad3584.scala
Exception in thread "main" java.lang.RuntimeException: Erasure should have added an unboxing operation to prevent this cast. Tree: TypeApply(Ident(asInstanceOf),List(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)]))
	at dotty.tools.backend.jvm.DottyBackendInterface.abort(DottyBackendInterface.scala:394)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genTypeApply(BCodeBodyBuilder.scala:599)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:428)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genStat(BCodeBodyBuilder.scala:77)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genNormalBlock$2$$anonfun$1(BCodeBodyBuilder.scala:860)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:389)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genNormalBlock$1(BCodeBodyBuilder.scala:860)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genBlock(BCodeBodyBuilder.scala:892)
	at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:408)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.emitNormalMethodBody$1(BCodeSkelBuilder.scala:602)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genDefDef(BCodeSkelBuilder.scala:635)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:506)
	at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen$$anonfun$1(BCodeSkelBuilder.scala:508)

RE-d341ba7adb385e80fb9955ca9161dd8f86ad3584

Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2018
@Blaisorblade
Copy link
Contributor

Ah, looks like TypeTestCasts.interceptTypeApply needs to use desugarIdent (see fix).

That's why asInstanceOf[Int] crashes while this.asInstanceOf[Int] doesn't — you sadly need to desugar on usage (#1686, #3925), lest you want to transform each identifier into a huge selection tree (for types we can do it, but types have no position and can be aggressively hash-consed).

@smarter
Copy link
Member

smarter commented Apr 30, 2019

@Blaisorblade Do you remember why you didn't end up making a PR for dotty-staging@6cc105c which should fix this ?

@Blaisorblade
Copy link
Contributor

@smarter I'm not sure; I think I ran out of steam on revising those fixes for inclusion :-|. But feel free to cherry-pick that commit...

@smarter
Copy link
Member

smarter commented Apr 30, 2019

OK, I'll have a look.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 17, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 17, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 17, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2019
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2019
nicolasstucki added a commit that referenced this issue Jul 18, 2019
Fix #5006: Enforce `asInstanceOf` to be a `Select` node
@nicolasstucki nicolasstucki reopened this Jul 18, 2019
nicolasstucki added a commit that referenced this issue Jul 18, 2019
…-fails

Revert "Fix #5006: Normalize prefixes of TypeApply in Erasure"
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2019
nicolasstucki added a commit that referenced this issue Jul 22, 2019
Fix #5006: Normalize prefixes of TypeApply in Erasure
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

4 participants