Skip to content

Commit f26a47c

Browse files
committed
Disallow eliding when Nothing is expected
1 parent fbb7865 commit f26a47c

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/compiler/scala/tools/nsc/backend/icode/GenICode.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ abstract class GenICode extends SubComponent {
885885
ctx.bb.emit(CONSTANT(global.gen.mkConstantZero(expectedType.toType)), tree.pos)
886886
generatedType = expectedType
887887
}
888+
else if (expectedType.isNothingType) unit.error(tree.pos, "Cannot elide where Nothing is required.")
888889
else {
889890
ctx.bb.emit(CONSTANT(Constant(null)), tree.pos)
890891
generatedType = NullReference
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
elide-to-nothing.scala:14: error: Cannot elide where Nothing is required.
2+
val b: Nothing = unimplemented()
3+
^
4+
one error found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xelide-below 500
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
/** Test which should fail compilation */
3+
class ElysianFailed {
4+
5+
import ElysianField._
6+
7+
// fine
8+
val a: Int = myInt
9+
10+
// fine
11+
unimplemented()
12+
13+
// not fine
14+
val b: Nothing = unimplemented()
15+
16+
}
17+
18+
object ElysianField {
19+
20+
import annotation.elidable
21+
22+
@elidable(100) def unimplemented(): Nothing = throw new UnsupportedOperationException
23+
24+
@elidable(100) def myInt: Int = 17
25+
26+
}
27+
28+
29+
30+
31+

0 commit comments

Comments
 (0)