diff options
author | odersky <odersky@gmail.com> | 2015-06-06 11:00:59 +0200 |
---|---|---|
committer | odersky <odersky@gmail.com> | 2015-06-06 11:00:59 +0200 |
commit | 6ca52b0f23f0c3425d054d0918a149e0e7afb765 (patch) | |
tree | 2feaae75dc15cde118cc7fafc5912fa50247d3bd /tests | |
parent | c0770edba1f5ba85b5a48f2c2ce68704dbe00087 (diff) | |
parent | 0cdb29904affbf55d5f08a005e8b96acfd73aa81 (diff) | |
download | dotty-6ca52b0f23f0c3425d054d0918a149e0e7afb765.tar.gz dotty-6ca52b0f23f0c3425d054d0918a149e0e7afb765.tar.bz2 dotty-6ca52b0f23f0c3425d054d0918a149e0e7afb765.zip |
Merge pull request #622 from dotty-staging/add/implement-scala2-traits
Implement Scala2 traits
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pos/scala2traits/dotty-subclass.scala | 27 | ||||
-rw-r--r-- | tests/pos/scala2traits/scala-trait.scala | 31 | ||||
-rw-r--r-- | tests/run/t6534.scala | 10 |
3 files changed, 66 insertions, 2 deletions
diff --git a/tests/pos/scala2traits/dotty-subclass.scala b/tests/pos/scala2traits/dotty-subclass.scala new file mode 100644 index 000000000..4e162dd14 --- /dev/null +++ b/tests/pos/scala2traits/dotty-subclass.scala @@ -0,0 +1,27 @@ +// This is supposed to be compiled by Dotty +class Sub extends T + +class A extends S2T with S2Tprivate { + val a: Int = 3 + var b = 2 +} + +object Main { + def main(args: Array[String]): Unit = { + val sub = new Sub + println(sub.d) + println(sub.v) + println(sub.O) + println(sub.w) + + val a = new A + a.x += a.y + println(a.x) + println(a.f(a.a + a.b)) + + a.xx += a.yy + println(a.x) + println(a.ff(a.xx)) + } +} + diff --git a/tests/pos/scala2traits/scala-trait.scala b/tests/pos/scala2traits/scala-trait.scala new file mode 100644 index 000000000..db05bc941 --- /dev/null +++ b/tests/pos/scala2traits/scala-trait.scala @@ -0,0 +1,31 @@ +// This is supposed to be compiled by Scala 2.11 +trait T { + def d = 42 + val v = "" + object O + final val w = 33 +} + +trait S2T { + var x: Int = 0 + lazy val y: Int = 1 +// val z: Int = 2 + val a: Int + var b: Int + + def f(x: Int): Int = x + y +} + +trait S2Tprivate { + private var x: Int = 0 + private lazy val y: Int = 1 +// private val z: Int = 2 // @darkdimius uncomment once lazy vals can be inherited. + + private def f(x: Int): Int = x + y + def xx = x + def xx_=(x: Int) = this.x = x + def yy = y +// def zz = z + def ff(x: Int) = f(x) +} + diff --git a/tests/run/t6534.scala b/tests/run/t6534.scala index 33df97e41..b5789f52c 100644 --- a/tests/run/t6534.scala +++ b/tests/run/t6534.scala @@ -8,7 +8,13 @@ object Test { def main(args: Array[String]): Unit = { val b1 = new Bippy1(71) val b2 = new Bippy2(71) - assert(b1 == b1 && b1.## == b1.x.##, ((b1, b1.##))) - assert(b2 == b2 && b2.## == b2.x.##, ((b2, b2.##))) + assert(b1 == b1) + assert(b1.## == b1.x.##, "hash differs1 " + ((b1, b1.##))) + assert(b2 == b2) + // assert(b2.## == b2.x.##, "hash differs2 " + ((b2, b2.##, b2.x.##))) + // Disabled, this does not hold. Because the value class inherits + // a different hashCode, no code is generated for it. Replaced by: + assert(b2.## == -1) + assert(!b1.equals(b1)) } } |