diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-08-28 16:15:43 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-11 23:22:07 +0200 |
commit | 38a488ea17e4ed42b65df4095c2eac738a63f5c4 (patch) | |
tree | 703be8007786ac12ebe70274b6c580c76096e869 | |
parent | f04257b8414745d8e13bee213e551ef01c839602 (diff) | |
download | scala-38a488ea17e4ed42b65df4095c2eac738a63f5c4.tar.gz scala-38a488ea17e4ed42b65df4095c2eac738a63f5c4.tar.bz2 scala-38a488ea17e4ed42b65df4095c2eac738a63f5c4.zip |
SI-7007 Test case shows we disallow premature `this` access
Rather than the old behaviour, which compiled successfully
but led us into the jaws of a LinkageError.
Related to SI-6666.
-rw-r--r-- | test/files/neg/t7007.check | 7 | ||||
-rw-r--r-- | test/files/neg/t7007.scala | 14 |
2 files changed, 21 insertions, 0 deletions
diff --git a/test/files/neg/t7007.check b/test/files/neg/t7007.check new file mode 100644 index 0000000000..e22ecb9e4e --- /dev/null +++ b/test/files/neg/t7007.check @@ -0,0 +1,7 @@ +t7007.scala:5: error: Implementation restriction: <$anon: A => B> requires premature access to class Crash. + def this(a: Seq[A]) = this(a.collect{ case b: B => b}, a.collect{ case b: B => b}) + ^ +t7007.scala:5: error: Implementation restriction: <$anon: A => B> requires premature access to class Crash. + def this(a: Seq[A]) = this(a.collect{ case b: B => b}, a.collect{ case b: B => b}) + ^ +two errors found diff --git a/test/files/neg/t7007.scala b/test/files/neg/t7007.scala new file mode 100644 index 0000000000..e41dccf550 --- /dev/null +++ b/test/files/neg/t7007.scala @@ -0,0 +1,14 @@ +class A +class B extends A + +class Crash(b1: Seq[B], b2: Seq[B]) { + def this(a: Seq[A]) = this(a.collect{ case b: B => b}, a.collect{ case b: B => b}) +} + +object Main extends App { + + // runtime exception with either constructor + val c1 = new Crash(Seq(new B, new B)) + val c2 = new Crash(Seq(new B), Seq(new B)) + +} |