From f324ca5e14d29f8b4f6f7bbacc1c17f4233cd260 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Wed, 20 Aug 2014 13:17:16 +0200 Subject: SI-8803 generate super accessor for super[A], if A is outer superclass class C extends A with T { class I { C.super[T] C.super[A] } } A super call in a nested class of the form super[T] where T is a parent trait of the outer class doesn't need an accessor: mixin can directly re-route the call to the correct implementation class - it's statically known to be T$class. However, if a nested class accesses super[A] and A is the superclass of the outer class (not a trait), then we need a super accessor in the outer class. We need to add the mixin name to the super accessor name, otherwise it clashes with non-qualified super accessors. --- test/files/run/t8803.check | 16 +++++++++++++ test/files/run/t8803.scala | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 test/files/run/t8803.check create mode 100644 test/files/run/t8803.scala (limited to 'test') diff --git a/test/files/run/t8803.check b/test/files/run/t8803.check new file mode 100644 index 0000000000..bd26a0fb14 --- /dev/null +++ b/test/files/run/t8803.check @@ -0,0 +1,16 @@ +a +b +b +c +a +b +b +c +a +b +b +c +a +b +b +c diff --git a/test/files/run/t8803.scala b/test/files/run/t8803.scala new file mode 100644 index 0000000000..2e56180502 --- /dev/null +++ b/test/files/run/t8803.scala @@ -0,0 +1,57 @@ +class A { + def m = "a" + protected def n = "a" +} + +trait B { + def m = "b" + protected def n = "b" +} + +class C extends A with B { + override def m = "c" + override protected def n = "c" + + val f1 = () => super[A].m + val f2 = () => super[B].m + val f3 = () => super.m + val f4 = () => this.m + + val g1 = new runtime.AbstractFunction0[String] { def apply() = C.super[A].m } + val g2 = new runtime.AbstractFunction0[String] { def apply() = C.super[B].m } + val g3 = new runtime.AbstractFunction0[String] { def apply() = C.super.m } + val g4 = new runtime.AbstractFunction0[String] { def apply() = C.this.m } + + val h1 = () => super[A].n + val h2 = () => super[B].n + val h3 = () => super.n + val h4 = () => this.n + + val i1 = new runtime.AbstractFunction0[String] { def apply() = C.super[A].n } + val i2 = new runtime.AbstractFunction0[String] { def apply() = C.super[B].n } + val i3 = new runtime.AbstractFunction0[String] { def apply() = C.super.n } + val i4 = new runtime.AbstractFunction0[String] { def apply() = C.this.n } +} + +object Test extends App { + val c = new C + println(c.f1()) + println(c.f2()) + println(c.f3()) + println(c.f4()) + + println(c.g1()) + println(c.g2()) + println(c.g3()) + println(c.g4()) + + println(c.h1()) + println(c.h2()) + println(c.h3()) + println(c.h4()) + + println(c.i1()) + println(c.i2()) + println(c.i3()) + println(c.i4()) +} -- cgit v1.2.3