From ee93df064b8b48f9e600d5ea99a0ebc5e0848345 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Mon, 23 Jul 2012 11:14:47 +0200 Subject: SI-4440 workaround: avoid outer accessor that'll vanish outer accessors of final classes are dropped in constructors apply some foresight in explicit outer and replace those doomed outer checks by `true` (since this is unfortunate, we generate an unchecked warning) --- test/files/neg/t4440.check | 13 +++++++++++++ test/files/neg/t4440.flags | 1 + test/files/neg/t4440.scala | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 test/files/neg/t4440.check create mode 100644 test/files/neg/t4440.flags create mode 100644 test/files/neg/t4440.scala (limited to 'test/files/neg') diff --git a/test/files/neg/t4440.check b/test/files/neg/t4440.check new file mode 100644 index 0000000000..2861dc3040 --- /dev/null +++ b/test/files/neg/t4440.check @@ -0,0 +1,13 @@ +t4440.scala:12: error: The outer reference in this type test cannot be checked at run time. + case _: b.Inner => println("b") + ^ +t4440.scala:13: error: The outer reference in this type test cannot be checked at run time. + case _: a.Inner => println("a") // this is the case we want + ^ +t4440.scala:16: error: The outer reference in this type test cannot be checked at run time. + case _: a.Inner => println("a") + ^ +t4440.scala:17: error: The outer reference in this type test cannot be checked at run time. + case _: b.Inner => println("b") // this is the case we want + ^ +four errors found diff --git a/test/files/neg/t4440.flags b/test/files/neg/t4440.flags new file mode 100644 index 0000000000..779916d58f --- /dev/null +++ b/test/files/neg/t4440.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings \ No newline at end of file diff --git a/test/files/neg/t4440.scala b/test/files/neg/t4440.scala new file mode 100644 index 0000000000..383b141edd --- /dev/null +++ b/test/files/neg/t4440.scala @@ -0,0 +1,19 @@ +// constructors used to drop outer fields when they were not accessed +// however, how can you know (respecting separate compilation) that they're not accessed!? +class Outer { final class Inner } + +// the matches below require Inner's outer pointer +// until SI-4440 is fixed properly, we can't make this a run test +// in principle, the output should be "a\nb", but without outer checks it's "b\na" +object Test extends App { + val a = new Outer + val b = new Outer + (new a.Inner: Any) match { + case _: b.Inner => println("b") + case _: a.Inner => println("a") // this is the case we want + } + (new b.Inner: Any) match { + case _: a.Inner => println("a") + case _: b.Inner => println("b") // this is the case we want + } +} -- cgit v1.2.3