diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2015-05-27 20:41:41 +0200 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2015-05-28 02:28:27 +0200 |
commit | beba9703e6a8cfd9d0f541c6a75125cef9eff726 (patch) | |
tree | ec9a59ad7d78a6c3d62c4be10eedd84e3773acfd /tests/run/paramForwarding.scala | |
parent | c0b693060c666f66cc5f26462e95f74b68975f31 (diff) | |
download | dotty-beba9703e6a8cfd9d0f541c6a75125cef9eff726.tar.gz dotty-beba9703e6a8cfd9d0f541c6a75125cef9eff726.tar.bz2 dotty-beba9703e6a8cfd9d0f541c6a75125cef9eff726.zip |
ParamForwarding: do not require param accessors to be private[this]
Also mark the forwarder as Stable otherwise we get a RefChecks error.
This fixes #608.
Note that we do less parameter forwarding than scalac. See for example D
and Y in tests/run/paramForwarding.scala which don't get their own local
fields in scalac but do in dotty.
Diffstat (limited to 'tests/run/paramForwarding.scala')
-rw-r--r-- | tests/run/paramForwarding.scala | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/run/paramForwarding.scala b/tests/run/paramForwarding.scala new file mode 100644 index 000000000..61466b621 --- /dev/null +++ b/tests/run/paramForwarding.scala @@ -0,0 +1,89 @@ +// A contains a field A.theValue$$local accessible using the +// generated getter A.theValue() +class A(val theValue: Int) { + val theValueInA = theValue // use the constructor parameter theValue + + def getTheValue = theValue // virtual call to the getter theValue() +} + +// B contains a field B.theValue$$local accessible using the getter +// B.theValue() which overrides A.theValue() +class B(override val theValue: Int) extends A(42) { + val theValueInB = theValue +} + +// Bz contains a field Bz.theValue$$local accessible using the getter +// Bz.theValue() which overrides A.theValue() +class Bz extends A(42) { + override val theValue: Int = 10 + val theValueInBz = theValue +} + +// C does not contains a field C.theValue$$local, it contains +// a getter C.theValue() which only calls super.theValue() +class C(override val theValue: Int) extends A(theValue) + +// D contains a field D.other$$local and a corresponding getter. +class D(val other: Int) extends A(other) + + +// NonVal does not contain a field NonVal.theValue$$local. +class NonVal(theValue: Int) extends A(theValue) { + def getTheValueInNonVal = theValue // use the constructor parameter theValue +} + +// X contains a field X.theValue$$local accessible using the getter +// X.theValue() which overrides A.theValue() +class X(override val theValue: Int) extends NonVal(0) + +// Y contains a field Y.theValue$$local accessible using the getter +// Y.theValue() which overrides A.theValue() +class Y(override val theValue: Int) extends NonVal(theValue) + + +object Test { + def printFields(obj: Any) = + println(obj.getClass.getDeclaredFields.map(_.toString).sorted.deep.mkString("\n")) + + def main(args: Array[String]): Unit = { + val b10 = new B(10) + val bz = new Bz + val c11 = new C(11) + val d12 = new D(12) + val nv13 = new NonVal(13) + val x14 = new X(14) + val y15 = new Y(15) + + println("B:") + printFields(b10) + println("Bz:") + printFields(bz) + println("C:") + printFields(c11) + println("D:") + printFields(d12) + println("NonVal:") + printFields(nv13) + println("X:") + printFields(x14) + println("Y:") + printFields(y15) + + + assert(b10.getTheValue == 10) + assert(b10.theValue == 10) + assert(b10.theValueInB == 10) + assert(b10.theValueInA == 42) + + assert(bz.getTheValue == 10) + assert(bz.theValue == 10) + assert(bz.theValueInBz == 10) + assert(bz.theValueInA == 42) + + + assert(x14.theValue == 14) + assert(x14.getTheValue == 14) + assert(x14.getTheValueInNonVal == 0) + assert(x14.theValueInA == 0) + } +} |