aboutsummaryrefslogtreecommitdiff
path: root/tests/run
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-06-20 00:44:47 +0200
committerMartin Odersky <odersky@gmail.com>2015-06-20 00:45:02 +0200
commit9a4b5e7c306eb3f1c82ace10dd62576473b1dec1 (patch)
tree9580b1faebdee6cd0a55cfba71526cb5046e3897 /tests/run
parentc093792189f49c3e72ada99ca0fdb97e4023ef78 (diff)
downloaddotty-9a4b5e7c306eb3f1c82ace10dd62576473b1dec1.tar.gz
dotty-9a4b5e7c306eb3f1c82ace10dd62576473b1dec1.tar.bz2
dotty-9a4b5e7c306eb3f1c82ace10dd62576473b1dec1.zip
Map outer fields to parameters in primary constructor
Previously this was only done in secondary constructors; need to do it in primary constructor as well to avoid "reference to this before super" problems.
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/NestedClasses.check9
-rw-r--r--tests/run/NestedClasses.scala97
-rw-r--r--tests/run/t8611b.flags1
-rw-r--r--tests/run/t8611b.scala54
4 files changed, 161 insertions, 0 deletions
diff --git a/tests/run/NestedClasses.check b/tests/run/NestedClasses.check
new file mode 100644
index 000000000..a7ebc386e
--- /dev/null
+++ b/tests/run/NestedClasses.check
@@ -0,0 +1,9 @@
+e.e1 = 119
+cc.m = 3
+cc.am = 1
+cc.bm = 2
+aaa.f = 111
+bbb1.f = 42
+bbb2.f = 24
+bbb3.f = 24
+bbb4.f = 24
diff --git a/tests/run/NestedClasses.scala b/tests/run/NestedClasses.scala
new file mode 100644
index 000000000..6db713e08
--- /dev/null
+++ b/tests/run/NestedClasses.scala
@@ -0,0 +1,97 @@
+//############################################################################
+// Test nested classes
+//############################################################################
+
+// The following set of classes tests nasty references to "outer"
+// values.
+
+class A(pa : Int) {
+ def a1 = pa;
+ class B(pb : Int) {
+ def b1 = pa+pb+a1;
+ class C(pc : Int) extends A(b1) {
+ def c1 = pc+pb+pa
+ }
+ val c1 = new C(13)
+ }
+}
+
+trait M {
+ def m1 = 1
+}
+
+class A1(x : Int) extends A(x) with M {
+ class D extends B(14) {
+ val c2 = new C(15);
+ class E extends C(16) {
+ def e1 = c1+b1+a1+m1;
+ def e2 = new D();
+ }
+ }
+}
+
+// The following set of classes test qualified "this" and "super"
+// references.
+
+class AA {
+ def m = 1;
+ class BB {
+ def m = 2;
+ class CC {
+ def m = 3;
+ def am = AA.this.m;
+ def bm = BB.this.m;
+ }
+ }
+}
+
+class AAA {
+ def f = 42;
+}
+
+class BBB extends AAA {
+ override def f = 24;
+}
+
+class AAA1 extends AAA {
+ override def f = 111;
+ class BBB1 extends BBB {
+ override def f = AAA1.super.f;
+ }
+ class BBB2 extends BBB {
+ override def f = BBB2.super.f;
+ }
+ class BBB3 extends BBB {
+ override def f = super.f;
+ }
+ class BBB4 extends BBB { }
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ val a = new A1(12);
+ val d = new a.D;
+ val e = new d.E;
+ Console.println("e.e1 = " + e.e1);
+
+ val aa = new AA;
+ val bb = new aa.BB;
+ val cc = new bb.CC;
+ Console.println("cc.m = " + cc.m);
+ Console.println("cc.am = " + cc.am);
+ Console.println("cc.bm = " + cc.bm);
+
+ val aaa = new AAA1;
+ val bbb1 = new aaa.BBB1;
+ val bbb2 = new aaa.BBB2;
+ val bbb3 = new aaa.BBB3;
+ val bbb4 = new aaa.BBB4;
+ Console.println("aaa.f = " + aaa.f);
+ Console.println("bbb1.f = " + bbb1.f);
+ Console.println("bbb2.f = " + bbb2.f);
+ Console.println("bbb3.f = " + bbb3.f);
+ Console.println("bbb4.f = " + bbb4.f);
+ }
+}
+
+//############################################################################
diff --git a/tests/run/t8611b.flags b/tests/run/t8611b.flags
new file mode 100644
index 000000000..85d8eb2ba
--- /dev/null
+++ b/tests/run/t8611b.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/tests/run/t8611b.scala b/tests/run/t8611b.scala
new file mode 100644
index 000000000..75114c2ae
--- /dev/null
+++ b/tests/run/t8611b.scala
@@ -0,0 +1,54 @@
+sealed trait KrafsDescription
+
+abstract class NotWorkingEnum extends Enumeration {
+
+ type ExtendedValue = Value with KrafsDescription
+
+ def Enum(inDescription: String): ExtendedValue = {
+ new Val(nextId) with KrafsDescription {
+ }
+ }
+}
+
+abstract class WorkingEnum extends Enumeration {
+
+ type ExtendedValue = Value
+
+ def Enum(inDescription: String): ExtendedValue = {
+ new Val(nextId) {
+ }
+ }
+}
+
+object NotWorkingTab extends NotWorkingEnum {
+ val a = Enum("A")
+ val b = Enum("B")
+}
+
+object WorkingTab extends WorkingEnum {
+ val a = Enum("A")
+ val b = Enum("B")
+}
+
+object Test extends dotty.runtime.LegacyApp {
+ testGris()
+ testWorking()
+
+ def testGris(): Unit = {
+ val pipp = NotWorkingTab.b
+ pipp match {
+ case NotWorkingTab.a => ???
+ case NotWorkingTab.b =>
+ case _ => ???
+ }
+ }
+
+ def testWorking(): Unit = {
+ val stuff = WorkingTab.a
+ stuff match {
+ case WorkingTab.a =>
+ case WorkingTab.b => ???
+ case _ => ???
+ }
+ }
+}