From 38a488ea17e4ed42b65df4095c2eac738a63f5c4 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 28 Aug 2013 16:15:43 +0200 Subject: 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. --- test/files/neg/t7007.check | 7 +++++++ test/files/neg/t7007.scala | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/files/neg/t7007.check create mode 100644 test/files/neg/t7007.scala (limited to 'test') 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)) + +} -- cgit v1.2.3