summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-06-17 23:23:49 +0200
committerJason Zaugg <jzaugg@gmail.com>2012-06-17 23:48:42 +0200
commit6aa5762fa0333625ec93378e2147649a8bafde34 (patch)
tree52c6c9c7d608e20d3c628d5f325977f834866a20 /test
parent277dc7cf43566f8294bde4143107d9bfaa59e8e3 (diff)
downloadscala-6aa5762fa0333625ec93378e2147649a8bafde34.tar.gz
scala-6aa5762fa0333625ec93378e2147649a8bafde34.tar.bz2
scala-6aa5762fa0333625ec93378e2147649a8bafde34.zip
SI-4842 Forbid access to in-construction this in self-constructor args
The check was already in place for direct calls to the super constructor. Without this additional check, ExplicitOuter crashes, as it doesn't create an $outer pointer for the constructor-arg scoped inner object, but expects one to exist when transforming the Outer.this reference.
Diffstat (limited to 'test')
-rw-r--r--test/files/neg/t4842a.check4
-rw-r--r--test/files/neg/t4842a.scala3
-rw-r--r--test/files/neg/t4842b.check4
-rw-r--r--test/files/neg/t4842b.scala3
-rw-r--r--test/files/pos/t4842.scala26
5 files changed, 40 insertions, 0 deletions
diff --git a/test/files/neg/t4842a.check b/test/files/neg/t4842a.check
new file mode 100644
index 0000000000..39d77bfc48
--- /dev/null
+++ b/test/files/neg/t4842a.check
@@ -0,0 +1,4 @@
+t4842a.scala:2: error: self constructor arguments cannot reference unconstructed `this`
+ def this(x: Int) = this(new { println(Foo.this)}) // error
+ ^
+one error found
diff --git a/test/files/neg/t4842a.scala b/test/files/neg/t4842a.scala
new file mode 100644
index 0000000000..78360effb4
--- /dev/null
+++ b/test/files/neg/t4842a.scala
@@ -0,0 +1,3 @@
+class Foo (x: AnyRef) {
+ def this(x: Int) = this(new { println(Foo.this)}) // error
+}
diff --git a/test/files/neg/t4842b.check b/test/files/neg/t4842b.check
new file mode 100644
index 0000000000..c7ccd5e059
--- /dev/null
+++ b/test/files/neg/t4842b.check
@@ -0,0 +1,4 @@
+t4842b.scala:2: error: self constructor arguments cannot reference unconstructed `this`
+ def this() = { this(???)(new { println(TypeArg.this.x) } ); println("next") } // error
+ ^
+one error found
diff --git a/test/files/neg/t4842b.scala b/test/files/neg/t4842b.scala
new file mode 100644
index 0000000000..a7996cc061
--- /dev/null
+++ b/test/files/neg/t4842b.scala
@@ -0,0 +1,3 @@
+class TypeArg[X](val x: X)(a: AnyRef) {
+ def this() = { this(???)(new { println(TypeArg.this.x) } ); println("next") } // error
+}
diff --git a/test/files/pos/t4842.scala b/test/files/pos/t4842.scala
new file mode 100644
index 0000000000..17ff684833
--- /dev/null
+++ b/test/files/pos/t4842.scala
@@ -0,0 +1,26 @@
+class Foo (x: AnyRef) {
+ def this() = {
+ this(new { } ) // okay
+ }
+}
+
+
+class Blerg (x: AnyRef) {
+ def this() = {
+ this(new { class Bar { println(Bar.this); new { println(Bar.this) } }; new Bar } ) // okay
+ }
+}
+
+
+class Outer {
+ class Inner (x: AnyRef) {
+ def this() = {
+ this(new { class Bar { println(Bar.this); new { println(Bar.this) } }; new Bar } ) // okay
+ }
+
+ def this(x: Boolean) = {
+ this(new { println(Outer.this) } ) // okay
+ }
+ }
+}
+