Skip to content
Browse files

overzealous assert in BCodeBodyBuilder rejected throw null

  • Loading branch information...
1 parent 841dbc9 commit f9cbcbdaf81800b98a6774ca1e1dffcf2875fe4e @magarciaEPFL magarciaEPFL committed Aug 30, 2013
View
4 src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
@@ -88,7 +88,9 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
def genThrow(expr: Tree): BType = {
val thrownKind = tpeTK(expr)
- assert(exemplars.get(thrownKind).isSubtypeOf(ThrowableReference))
+ // `throw null` is valid although scala.Null (as defined in src/libray-aux) isn't a subtype of Throwable.
+ // Similarly for scala.Nothing (again, as defined in src/libray-aux).
+ assert(thrownKind.isNullType || thrownKind.isNothingType || exemplars.get(thrownKind).isSubtypeOf(ThrowableReference))
genLoad(expr, thrownKind)
lineNumber(expr)
emit(asm.Opcodes.ATHROW) // ICode enters here into enterIgnoreMode, we'll rely instead on DCE at ClassNode level.
View
7 test/files/pos/bcode_throw_null/TN.scala
@@ -0,0 +1,7 @@
+object TN {
+
+ def pre1(b: Boolean) {
+ println(if (b) 1 else throw null)
+ }
+
+}

0 comments on commit f9cbcbd

Please sign in to comment.
Something went wrong with that request. Please try again.