Skip to content

Commit ab197fb

Browse files
authored
Merge pull request #1 from EnzeXing/EnzeXing-tests-for-dotty
Add test cases for dotty
2 parents a00fb3f + f55d373 commit ab197fb

9 files changed

+123
-0
lines changed

tests/init/neg/Desugar.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait A
2+
3+
class Tree[-A >: Int] {
4+
val x: Int = 10
5+
}
6+
7+
case class C[-T >: Int] (lhs: Int, rhs: Tree[T]) extends A {
8+
val x = rhs.x
9+
}
10+
11+
object DesugarError {
12+
val f: PartialFunction[A, Int] = {case C(_, rhs) => rhs.x}
13+
}
14+
15+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
trait InteractiveDriver[A <: AnyVal] {
2+
val x: AnyVal
3+
def g(x: A): A
4+
}
5+
6+
class C[A <: AnyVal] extends InteractiveDriver[A] {
7+
val x = 0
8+
def g(x: A) = x
9+
}
10+
11+
class D[A <: AnyVal] extends InteractiveDriver[A] {
12+
val x = 1.5
13+
def g(x: A) = x
14+
}
15+
16+
object InteractiveDriver {
17+
def h(x: InteractiveDriver[?]): C[?] = x match {
18+
case c: C[?] => c
19+
case _ => new C[Int]
20+
}
21+
val l: Seq[Any] = Seq(1, 2, new C[Double], new D[Int])
22+
val l2: Seq[C[?]] = l.collect{ case x: InteractiveDriver[?] => h(x) }
23+
}

tests/init/neg/closureLeak.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Outer {
2+
val x = 10
3+
class A(x: Int) {
4+
var y: Int = x
5+
def addX(o: Outer): Unit = {
6+
y = y + o.x
7+
}
8+
}
9+
10+
val l: List[A] = List(new A(5), new A(10))
11+
l.foreach(a => a.addX(this))
12+
}

tests/init/neg/default-this.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class A {
2+
var x: Int = 10
3+
def compare(c: Int = 5, a: A = this): Boolean = if (c == a.x) true else false
4+
}
5+
6+
class B extends A {
7+
def updateThenCompare(c: Int): Boolean = {
8+
x = c
9+
compare()
10+
}
11+
val result = updateThenCompare(5)
12+
}

tests/init/neg/enum.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
2+
case
3+
LazyErrorId, // // errorNumber: -2
4+
NoExplanationID
5+
def errorNumber = ordinal - 2
6+
}

tests/init/neg/leak-this-inner.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class A {
2+
val x = 10
3+
class B(a: A) {
4+
val anotherX = A.this.x
5+
}
6+
val b = B(this)
7+
val xAgain = b.anotherX
8+
}

tests/init/neg/leak-this.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Parent {
2+
val child: Child = new Child(this)
3+
}
4+
5+
class Child(parent: Parent) {
6+
val friend = new Friend(this.parent)
7+
}
8+
9+
class Friend(parent: Parent) {
10+
val tag = 10
11+
}

tests/init/neg/leak-warm.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
object leakWarm {
2+
abstract class A(tag: Int) {
3+
class B(x: Int) {
4+
val y = x
5+
}
6+
def m(): B
7+
}
8+
9+
class C(tag1: Int, tag2: Int) extends A(tag1) {
10+
def m() = new B(5)
11+
}
12+
13+
class D(tag1: Int, tag2: Int) extends A(tag1 + tag2) {
14+
def m() = new B(tag1)
15+
}
16+
val c = new C(1, 2)
17+
val d = new D(3, 4)
18+
val l: List[A] = List(c, d)
19+
val l2 = l.map(_.m())
20+
}

tests/init/neg/local-warm.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
abstract class A {
2+
def m() = 10
3+
def m1(): B = new B
4+
def m2(): Int = m1().m()
5+
class B extends A {
6+
def x = 10
7+
}
8+
}
9+
10+
class C extends A {
11+
def g() = {
12+
val t = m1()
13+
t.x
14+
}
15+
val x = g()
16+
}

0 commit comments

Comments
 (0)