diff options
author | Samuel Gruetter <samuel.gruetter@epfl.ch> | 2014-03-12 22:44:33 +0100 |
---|---|---|
committer | Samuel Gruetter <samuel.gruetter@epfl.ch> | 2014-03-12 22:44:33 +0100 |
commit | 9ef5f6817688f814a3450126aa7383b0928e80a0 (patch) | |
tree | 5727a2f7f7fd665cefdb312af2785c692f04377c /tests/untried/neg/t4762.scala | |
parent | 194be919664447631ba55446eb4874979c908d27 (diff) | |
download | dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.gz dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.bz2 dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.zip |
add tests from scala/test/files/{pos,neg}
with explicit Unit return type
Diffstat (limited to 'tests/untried/neg/t4762.scala')
-rw-r--r-- | tests/untried/neg/t4762.scala | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/untried/neg/t4762.scala b/tests/untried/neg/t4762.scala new file mode 100644 index 000000000..07b3152a6 --- /dev/null +++ b/tests/untried/neg/t4762.scala @@ -0,0 +1,51 @@ +// https://issues.scala-lang.org/browse/SI-4762 + +// In A, x and y are -1. +class A(var x: Int) { + val y: Int = -1 +} + +// In B, x and y are 99 and private[this], implicitly so +// in the case of x. +class B(x: Int) extends A(-1) { + private[this] def y: Int = 99 + + // Three distinct results. + def f = List( + /* (99,99) */ (this.x, this.y), + /* (-1,99) */ ((this: B).x, (this: B).y), + /* (-1,-1) */ ((this: A).x, (this: A).y) + ) + + // The 99s tell us we are reading the private[this] + // data of a different instance. + def g(b: B) = List( + /* (-1,99) */ (b.x, b.y), + /* (-1,99) */ ((b: B).x, (b: B).y), + /* (-1,-1) */ ((b: A).x, (b: A).y) + ) +} + +object Test { + def f(x: A) = /* -2 */ x.x + x.y + def g1(x: B) = /* -2 */ (x: A).x + (x: A).y + def g2(x: B) = (x: B).x + (x: B).y + // java.lang.IllegalAccessError: tried to access method B.y()I from class Test$ + + def main(args: Array[String]): Unit = { + val b = new B(99) + b.f foreach println + b.g(new B(99)) foreach println + + println(f(b)) + println(g1(b)) + println(g2(b)) + } +} + +class bug4762 { + class Base( var x : Int ) { def increment(): Unit = { x = x + 1 } } + class Derived( x : Int ) extends Base( x ) { override def toString = x.toString } + + val derived = new Derived( 1 ) +} |