From 582c8a2fdd1d5b3cacff982b0c4af0a7dd37b651 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 17 Nov 2016 13:20:30 -0800 Subject: SI-10068 Only permit elidable methods In refchecks, check that symbol with `@elidable` is a method. When eliding in uncurry, doublecheck. The check is enabled under `-Xsource:2.13`. --- test/files/neg/t10068.check | 13 +++++++++++++ test/files/neg/t10068.flags | 1 + test/files/neg/t10068.scala | 9 +++++++++ test/files/run/elidable.flags | 2 +- test/files/run/elidable.scala | 21 +++++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/files/neg/t10068.check create mode 100644 test/files/neg/t10068.flags create mode 100644 test/files/neg/t10068.scala (limited to 'test') diff --git a/test/files/neg/t10068.check b/test/files/neg/t10068.check new file mode 100644 index 0000000000..2bb27c4fd8 --- /dev/null +++ b/test/files/neg/t10068.check @@ -0,0 +1,13 @@ +t10068.scala:5: error: i : Only methods can be marked @elidable. + @elidable(INFO) val i: Int = 42 + ^ +t10068.scala:6: error: j: Only methods can be marked @elidable. + @elidable(INFO) lazy val j: Int = 42 + ^ +t10068.scala:7: error: k : Only methods can be marked @elidable. + @elidable(INFO) var k: Int = 42 + ^ +t10068.scala:9: error: D: Only methods can be marked @elidable. +@elidable(INFO) class D + ^ +four errors found diff --git a/test/files/neg/t10068.flags b/test/files/neg/t10068.flags new file mode 100644 index 0000000000..2b18795468 --- /dev/null +++ b/test/files/neg/t10068.flags @@ -0,0 +1 @@ +-Xelide-below WARNING -Xsource:2.13 diff --git a/test/files/neg/t10068.scala b/test/files/neg/t10068.scala new file mode 100644 index 0000000000..a45ee5dac4 --- /dev/null +++ b/test/files/neg/t10068.scala @@ -0,0 +1,9 @@ + +import annotation._, elidable._ + +class C { + @elidable(INFO) val i: Int = 42 + @elidable(INFO) lazy val j: Int = 42 + @elidable(INFO) var k: Int = 42 +} +@elidable(INFO) class D diff --git a/test/files/run/elidable.flags b/test/files/run/elidable.flags index 93fd3d5317..4bebebdc41 100644 --- a/test/files/run/elidable.flags +++ b/test/files/run/elidable.flags @@ -1 +1 @@ --Xelide-below 900 +-Xelide-below WARNING diff --git a/test/files/run/elidable.scala b/test/files/run/elidable.scala index 6a603084b7..02785972bb 100644 --- a/test/files/run/elidable.scala +++ b/test/files/run/elidable.scala @@ -1,6 +1,8 @@ import annotation._ import elidable._ +// runs -Xelide-below WARNING or 900 + trait T { @elidable(FINEST) def f1() @elidable(SEVERE) def f2() @@ -38,6 +40,13 @@ object Test { @elidable(FINEST) def fd() = 1.0 @elidable(FINEST) def fe() = "s" + /* variable elisions? see test/files/neg/t10068.scala + @elidable(INFO) val goner1: Int = { assert(false, "Should have been elided.") ; 42 } + @elidable(INFO) lazy val goner2: Int = { assert(false, "Should have been elided.") ; 42 } + @elidable(INFO) var goner3: Int = { assert(false, "Should have been elided.") ; 42 } + @elidable(INFO) var goner4: Nothing = _ + */ + def main(args: Array[String]): Unit = { f1() f2() @@ -80,5 +89,17 @@ object Test { Class.forName(className).getMethod(methodName) } } + + // variable elisions? + /* + assert(goner1 == 0) + assert(goner2 == 0) + assert(goner3 == 0) + try assert(goner4 == null) + catch { + case _: NullPointerException => println("NPE") + case _: NotImplementedError => println("NIE") + } + */ } } -- cgit v1.2.3