Skip to content

Commit 030eab9

Browse files
Add test cases
1 parent 06f311c commit 030eab9

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ matchtype.scala
2626
i7087.scala
2727
i7868.scala
2828
i7872.scala
29+
6709.scala
2930

3031
# Opaque type
3132
i5720.scala

tests/neg/6709.scala

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
object Test {
2+
type M[X] = X match {
3+
case Int => String
4+
case Double => Int
5+
}
6+
7+
def m_OK[X](x: X): M[X] = x match {
8+
case _: Int => ""
9+
case _: Double => 1
10+
}
11+
12+
def m_error0[X](x: X): M[X] = x match {
13+
case Some(i: Int) => "" // error
14+
case _: Double => 1 // error
15+
}
16+
17+
def m_error1[X](x: X): M[X] = x match {
18+
case s: String => "" // error
19+
case _: Double => 1 // error
20+
}
21+
22+
def m_error2[X](x: X): M[X] = x match {
23+
case _: Double => 1 // error
24+
case _: Int => "" // error
25+
}
26+
27+
def m_error3[X](x: X): M[X] = x match {
28+
case _: Int => "" // error
29+
}
30+
31+
def m_error4[X](x: X): M[X] = x match {
32+
case _: Int => "" // error
33+
case _: Double => 1 // error
34+
case _: String => true // error
35+
}
36+
37+
def m_error5[X](x: X): M[X] = x match {
38+
case _: Int if true => "" // error
39+
case _: Double => 1 // error
40+
}
41+
42+
case class Blah[A, B](a: A, b: B)
43+
44+
type LeafElem[X] = X match {
45+
case Array[t] => t
46+
case Blah[a, b] => a
47+
}
48+
49+
def leafElem_ok[X](x: X): LeafElem[X] = x match {
50+
case y: Array[t] => y.apply(0)
51+
case y: Blah[a, b] => y.a
52+
}
53+
54+
def leafElem_error[X](x: X): LeafElem[X] = x match {
55+
case y: Array[t] => 0 // error
56+
case y: Blah[a, b] => y.b // error
57+
}
58+
}

tests/pos/6709.scala

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
object Foo {
2+
type LeafElem[X] = X match {
3+
case String => Char
4+
case Array[t] => LeafElem[t]
5+
case Iterable[t] => LeafElem[t]
6+
case AnyVal => X
7+
}
8+
9+
def leafElem[X](x: X): LeafElem[X] =
10+
x match {
11+
case x: String => x.charAt(0)
12+
case x: Array[t] => leafElem(x(0))
13+
case x: Iterable[t] => leafElem(x.head)
14+
case _: AnyVal => x
15+
}
16+
17+
def leafElem2[X](x: X): LeafElem[X] =
18+
x match {
19+
case _: String => leafElem[X](x)
20+
case w: Array[t] => leafElem[X](x)
21+
}
22+
}
23+
24+
object Bar {
25+
import compiletime.S
26+
27+
type Plus[A <: Int, B <: Int] <: Int =
28+
A match {
29+
case 0 => B
30+
case S[p] => S[Plus[p, B]]
31+
}
32+
33+
def plus[A <: Int, B <: Int](a: A, b: B): Plus[A, B] =
34+
a match {
35+
case _: 0 => b
36+
case a: S[p] => succ(plus(pred(a), b))
37+
}
38+
39+
def pred[X <: Int](x: S[X]): X = (x - 1).asInstanceOf
40+
def succ[X <: Int](x: X): S[X] = (x + 1).asInstanceOf
41+
42+
val nine: 9 = plus[4, 5](4, 5)
43+
}
44+
45+
object Main {
46+
enum BinNat {
47+
case Zero
48+
// 2n + 1
49+
case Odd[N <: BinNat](n: N)
50+
// 2(n + 1)
51+
case Even[N <: BinNat](n: N)
52+
}
53+
54+
import BinNat._
55+
56+
type Inc[N <: BinNat] <: BinNat =
57+
N match {
58+
case Zero.type => Odd[Zero.type]
59+
case Odd[n] => Even[n]
60+
case Even[n] => Odd[Inc[n]]
61+
}
62+
63+
def inc[N <: BinNat](b: N): Inc[N] =
64+
b match {
65+
case _: Zero.type => new Odd(Zero)
66+
case o: Odd[n] => new Even(o.n)
67+
case e: Even[n] =>
68+
// 2(n + 1) + 1 = 2(inc(n)) + 1
69+
new Odd(inc(e.n))
70+
}
71+
}

0 commit comments

Comments
 (0)