summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Iry <jamesiry@gmail.com>2013-03-08 08:31:57 -0800
committerJames Iry <jamesiry@gmail.com>2013-03-08 08:31:57 -0800
commitfd21898db304f45fa12178662c9f1e5b793d6830 (patch)
treeccfb26864991002cc646adb1a11c5809584f5bfe
parent5967a664ab1129e28687c591bd94c0e482cb305f (diff)
downloadscala-fd21898db304f45fa12178662c9f1e5b793d6830.tar.gz
scala-fd21898db304f45fa12178662c9f1e5b793d6830.tar.bz2
scala-fd21898db304f45fa12178662c9f1e5b793d6830.zip
SI-7231 Fix assertion when adapting Null type to Array type
GenICode was doing a sanity check when adapting an expression of type Null to something else. It was just doing the wrong one. Instead of checking whether the result expression type was a reference type it was checking to see if it was an class reference type. This commit fixes that and adds a test to make sure both forms of adaptation work as expected.
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala2
-rw-r--r--test/files/run/t7231.check2
-rw-r--r--test/files/run/t7231.scala11
3 files changed, 14 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index ed458a4bbe..d4fa01e2f4 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1025,7 +1025,7 @@ abstract class GenICode extends SubComponent {
// this value into a local of type Null and we want the JVM to see that it's
// a null value so we don't have to also adapt local loads.
if (from == NullReference && to != UNIT && to != ObjectReference && to != AnyRefReference) {
- assert(to.isReferenceType, "Attempt to adapt a null to a non reference type $to.")
+ assert(to.isRefOrArrayType, s"Attempt to adapt a null to a non reference type $to.")
// adapt by dropping what we've got and pushing a null which
// will convince the JVM we really do have null
ctx.bb.emit(DROP(from), pos)
diff --git a/test/files/run/t7231.check b/test/files/run/t7231.check
new file mode 100644
index 0000000000..c1e4b6c175
--- /dev/null
+++ b/test/files/run/t7231.check
@@ -0,0 +1,2 @@
+null
+null
diff --git a/test/files/run/t7231.scala b/test/files/run/t7231.scala
new file mode 100644
index 0000000000..7d6bc81f3f
--- /dev/null
+++ b/test/files/run/t7231.scala
@@ -0,0 +1,11 @@
+object Test extends App {
+ val bar: Null = null
+
+ def foo(x: Array[Int]) = x
+ def baz(x: String) = x
+
+ // first line was failing
+ println(foo(bar))
+ // this line worked but good to have a double check
+ println(baz(bar))
+} \ No newline at end of file