diff options
author | Som Snytt <som.snytt@gmail.com> | 2012-02-21 12:01:27 -0800 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2012-02-21 12:01:27 -0800 |
commit | f26a47c4e8bda2f6c689b4e9b0bb5c64ccf4c699 (patch) | |
tree | 1b2bfc54bb5afed46813021fc00cb5b911215fbb | |
parent | fbb7865e137e83660257fdc79d19d29ff39c775b (diff) | |
download | scala-f26a47c4e8bda2f6c689b4e9b0bb5c64ccf4c699.tar.gz scala-f26a47c4e8bda2f6c689b4e9b0bb5c64ccf4c699.tar.bz2 scala-f26a47c4e8bda2f6c689b4e9b0bb5c64ccf4c699.zip |
Disallow eliding when Nothing is expected
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 1 | ||||
-rw-r--r-- | test/files/neg/elide-to-nothing.check | 4 | ||||
-rw-r--r-- | test/files/neg/elide-to-nothing.flags | 1 | ||||
-rw-r--r-- | test/files/neg/elide-to-nothing.scala | 31 |
4 files changed, 37 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index dd65e825c3..b9675b8270 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -885,6 +885,7 @@ abstract class GenICode extends SubComponent { ctx.bb.emit(CONSTANT(global.gen.mkConstantZero(expectedType.toType)), tree.pos) generatedType = expectedType } + else if (expectedType.isNothingType) unit.error(tree.pos, "Cannot elide where Nothing is required.") else { ctx.bb.emit(CONSTANT(Constant(null)), tree.pos) generatedType = NullReference diff --git a/test/files/neg/elide-to-nothing.check b/test/files/neg/elide-to-nothing.check new file mode 100644 index 0000000000..3ef05aac9a --- /dev/null +++ b/test/files/neg/elide-to-nothing.check @@ -0,0 +1,4 @@ +elide-to-nothing.scala:14: error: Cannot elide where Nothing is required. + val b: Nothing = unimplemented() + ^ +one error found diff --git a/test/files/neg/elide-to-nothing.flags b/test/files/neg/elide-to-nothing.flags new file mode 100644 index 0000000000..59a512e547 --- /dev/null +++ b/test/files/neg/elide-to-nothing.flags @@ -0,0 +1 @@ +-Xelide-below 500 diff --git a/test/files/neg/elide-to-nothing.scala b/test/files/neg/elide-to-nothing.scala new file mode 100644 index 0000000000..5008e8bc1d --- /dev/null +++ b/test/files/neg/elide-to-nothing.scala @@ -0,0 +1,31 @@ + +/** Test which should fail compilation */ +class ElysianFailed { + + import ElysianField._ + + // fine + val a: Int = myInt + + // fine + unimplemented() + + // not fine + val b: Nothing = unimplemented() + +} + +object ElysianField { + + import annotation.elidable + + @elidable(100) def unimplemented(): Nothing = throw new UnsupportedOperationException + + @elidable(100) def myInt: Int = 17 + +} + + + + + |