Skip to content

Commit 01bb05f

Browse files
committed
Fix match type reduction neg tests
1 parent 05e23b5 commit 01bb05f

File tree

9 files changed

+82
-64
lines changed

9 files changed

+82
-64
lines changed

tests/neg/11982.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ type Head[X] = X match {
44
}
55

66
object Unpair {
7-
def unpair[X <: Tuple2[Any, Any]]: Head[X] = 1
8-
unpair[Tuple2["msg", 42]]: "msg" // error
7+
def unpair[X <: Tuple2[Any, Any]]: Head[X] = 1 // error
8+
unpair[Tuple2["msg", 42]]: "msg"
99
}
1010

1111

@@ -14,8 +14,8 @@ type Head2[X] = X match {
1414
}
1515

1616
object Unpair2 {
17-
def unpair[X <: Tuple2[Tuple2[Any, Any], Tuple2[Any, Any]]]: Head2[X] = 1
18-
unpair[Tuple2[Tuple2["msg", 42], Tuple2[41, 40]]]: "msg" // error
17+
def unpair[X <: Tuple2[Tuple2[Any, Any], Tuple2[Any, Any]]]: Head2[X] = 1 // error
18+
unpair[Tuple2[Tuple2["msg", 42], Tuple2[41, 40]]]: "msg"
1919
}
2020

2121

@@ -35,6 +35,6 @@ type Head4[X] = X match {
3535
}
3636

3737
object Unpair4 {
38-
def unpair[X <: Foo[Any, Any]]: Head4[Foo[X, X]] = 1
39-
unpair[Foo["msg", 42]]: "msg" // error
38+
def unpair[X <: Foo[Any, Any]]: Head4[Foo[X, X]] = 1 // error
39+
unpair[Foo["msg", 42]]: "msg"
4040
}

tests/neg/6570-1.check

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
|
2525
| trying to reduce M[T]
2626
| failed since selector T
27-
| does not uniquely determine parameter x in
28-
| case Cov[x] => N[x]
29-
| The computed bounds for the parameter are:
30-
| x >: Box[Int]
27+
| does not match case Cov[x] => N[x]
28+
| and cannot be shown to be disjoint from it either.
3129
|
3230
| longer explanation available when compiling with `-explain`

tests/neg/i11982.check

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/neg/i11982.scala

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/neg/i11982a.check

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
|
88
| trying to reduce Tuple.Tail[X]
99
| failed since selector X
10-
| does not uniquely determine parameter xs in
11-
| case _ *: xs => xs
12-
| The computed bounds for the parameter are:
13-
| xs >: Any *: EmptyTuple.type <: Tuple
10+
| does not match case _ *: xs => xs
11+
| and cannot be shown to be disjoint from it either.
1412
|
1513
| longer explanation available when compiling with `-explain`
1614
-- [E057] Type Mismatch Error: tests/neg/i11982a.scala:10:38 -----------------------------------------------------------
@@ -22,10 +20,8 @@
2220
|
2321
| trying to reduce Tuple.Tail[X]
2422
| failed since selector X
25-
| does not uniquely determine parameter xs in
26-
| case _ *: xs => xs
27-
| The computed bounds for the parameter are:
28-
| xs >: Any *: EmptyTuple.type <: Tuple
23+
| does not match case _ *: xs => xs
24+
| and cannot be shown to be disjoint from it either.
2925
|
3026
| longer explanation available when compiling with `-explain`
3127
-- [E057] Type Mismatch Error: tests/neg/i11982a.scala:12:25 -----------------------------------------------------------
@@ -37,9 +33,7 @@
3733
|
3834
| trying to reduce Tuple.Tail[X]
3935
| failed since selector X
40-
| does not uniquely determine parameter xs in
41-
| case _ *: xs => xs
42-
| The computed bounds for the parameter are:
43-
| xs >: Any *: EmptyTuple.type <: Tuple
36+
| does not match case _ *: xs => xs
37+
| and cannot be shown to be disjoint from it either.
4438
|
4539
| longer explanation available when compiling with `-explain`

tests/neg/i13780.check

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i13780.scala:12:32 ------------------------------------------------------------
2+
12 | def unpair[X <: Y]: Head[X] = "" // error
3+
| ^^
4+
| Found: ("" : String)
5+
| Required: Head[X]
6+
|
7+
| where: X is a type in method unpair with bounds <: A.this.Y
8+
|
9+
|
10+
| Note: a match type could not be fully reduced:
11+
|
12+
| trying to reduce Head[X]
13+
| failed since selector X
14+
| does not match case (a, b) => a
15+
| and cannot be shown to be disjoint from it either.
16+
|
17+
| longer explanation available when compiling with `-explain`
118
-- [E007] Type Mismatch Error: tests/neg/i13780.scala:18:31 ------------------------------------------------------------
219
18 | def int[X <: Y]: Int = unpair[X] // error
320
| ^^^^^^^^^
@@ -11,11 +28,8 @@
1128
|
1229
| trying to reduce Head[X]
1330
| failed since selector X
14-
| does not uniquely determine parameters a, b in
15-
| case (a, b) => a
16-
| The computed bounds for the parameters are:
17-
| a >: Int
18-
| b >: Int
31+
| does not match case (a, b) => a
32+
| and cannot be shown to be disjoint from it either.
1933
|
2034
| longer explanation available when compiling with `-explain`
2135
-- [E007] Type Mismatch Error: tests/neg/i13780.scala:23:37 ------------------------------------------------------------
@@ -31,10 +45,7 @@
3145
|
3246
| trying to reduce Head[X]
3347
| failed since selector X
34-
| does not uniquely determine parameters a, b in
35-
| case (a, b) => a
36-
| The computed bounds for the parameters are:
37-
| a >: String
38-
| b >: String
48+
| does not match case (a, b) => a
49+
| and cannot be shown to be disjoint from it either.
3950
|
4051
| longer explanation available when compiling with `-explain`

tests/neg/i13780.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait Z {
99

1010
class A extends Z {
1111
type Y <: Tuple2[Any, Any]
12-
def unpair[X <: Y]: Head[X] = ""
12+
def unpair[X <: Y]: Head[X] = "" // error
1313
def any[X <: Y]: Any = unpair[X]
1414
}
1515

tests/pos/i15926.extract.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// like pos/i15926.scala
2+
// but with the nested match type extracted
3+
// which is a workaround that fixed the problem
4+
sealed trait Nat
5+
final case class Zero() extends Nat
6+
final case class Succ[+N <: Nat]() extends Nat
7+
8+
final case class Neg[+N <: Succ[Nat]]()
9+
10+
type Sum[X, Y] = Y match
11+
case Zero => X
12+
case Succ[y] => Sum[Succ[X], y]
13+
14+
type IntSum[A, B] = B match
15+
case Neg[b] => IntSumNeg[A, b]
16+
17+
type IntSumNeg[A, B] = A match
18+
case Neg[a] => Neg[Sum[a, B]]
19+
20+
type One = Succ[Zero]
21+
type Two = Succ[One]
22+
23+
class Test:
24+
def test() = summon[IntSum[Neg[One], Neg[One]] =:= Neg[Two]]

tests/pos/i15926.min.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// like pos/i15926.scala
2+
// but minimised to the subset of paths needed
3+
// to fail the specific test case
4+
sealed trait Nat
5+
final case class Zero() extends Nat
6+
final case class Succ[+N <: Nat]() extends Nat
7+
8+
final case class Neg[+N <: Succ[Nat]]()
9+
10+
type Sum[X, Y] = Y match
11+
case Zero => X
12+
case Succ[y] => Sum[Succ[X], y]
13+
14+
type IntSum[A, B] = B match
15+
case Neg[b] => A match
16+
case Neg[a] => Neg[Sum[a, b]]
17+
18+
type One = Succ[Zero]
19+
type Two = Succ[One]
20+
21+
class Test:
22+
def test() = summon[IntSum[Neg[One], Neg[One]] =:= Neg[Two]]

0 commit comments

Comments
 (0)