Skip to content

Commit 83af09e

Browse files
committed
Add regression tests for old issues fixed with the new match types.
Closes scala#17121. Closes scala#17944. Closes scala#18488.
1 parent 10bc31b commit 83af09e

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed

tests/neg/i17121.check

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- [E191] Type Error: tests/neg/i17121.scala:13:17 ---------------------------------------------------------------------
2+
13 | type G1[X] = X match { case Consumer[List[t]] => t } // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| The match type contains an illegal case:
5+
| case Consumer[List[t]] => t
6+
| (this error can be ignored for now with `-source:3.3`)
7+
-- [E191] Type Error: tests/neg/i17121.scala:15:17 ---------------------------------------------------------------------
8+
15 | type G2[X] = X match { case Consumer[Consumer[t]] => t } // error
9+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
| The match type contains an illegal case:
11+
| case Consumer[Consumer[t]] => t
12+
| (this error can be ignored for now with `-source:3.3`)
13+
-- [E191] Type Error: tests/neg/i17121.scala:17:17 ---------------------------------------------------------------------
14+
17 | type G3[X] = X match { case Consumer[Consumer[Consumer[t]]] => t } // error
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
| The match type contains an illegal case:
17+
| case Consumer[Consumer[Consumer[t]]] => t
18+
| (this error can be ignored for now with `-source:3.3`)
19+
-- [E191] Type Error: tests/neg/i17121.scala:19:17 ---------------------------------------------------------------------
20+
19 | type G4[X] = X match { case Consumer[List[Consumer[t]]] => t } // error
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
| The match type contains an illegal case:
23+
| case Consumer[List[Consumer[t]]] => t
24+
| (this error can be ignored for now with `-source:3.3`)

tests/neg/i17121.scala

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Consumer[-T]
2+
3+
object Test:
4+
type F1[X] = X match { case List[t] => t } // OK
5+
summon[F1[List[?]] =:= Any]
6+
7+
type F2[X] = X match { case Consumer[t] => t } // OK
8+
summon[F2[Consumer[?]] =:= Nothing]
9+
10+
type F3[X] = X match { case List[Consumer[t]] => t } // OK
11+
summon[F3[List[Consumer[?]]] =:= Nothing]
12+
13+
type G1[X] = X match { case Consumer[List[t]] => t } // error
14+
15+
type G2[X] = X match { case Consumer[Consumer[t]] => t } // error
16+
17+
type G3[X] = X match { case Consumer[Consumer[Consumer[t]]] => t } // error
18+
19+
type G4[X] = X match { case Consumer[List[Consumer[t]]] => t } // error
20+
end Test

tests/neg/i17944.check

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- [E172] Type Error: tests/neg/i17944.scala:40:87 ---------------------------------------------------------------------
2+
40 | val s = Selector.selectorInst[("s" ->> String) *: ("i" ->> Int) *: EmptyTuple, "i"] // error
3+
| ^
4+
|No singleton value available for Tuple.Elem[test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)], (1 : Int)]; eligible singleton types for `ValueOf` synthesis include literals and stable paths.
5+
|
6+
|Note: a match type could not be fully reduced:
7+
|
8+
| trying to reduce Tuple.Elem[test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)], (1 : Int)]
9+
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)]
10+
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
11+
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
12+
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
13+
| and cannot be shown to be disjoint from it either.
14+
| Therefore, reduction cannot advance to the remaining case
15+
|
16+
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
17+
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)]
18+
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
19+
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
20+
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
21+
| and cannot be shown to be disjoint from it either.
22+
| Therefore, reduction cannot advance to the remaining case
23+
|
24+
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
25+
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
26+
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
27+
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
28+
| and cannot be shown to be disjoint from it either.
29+
| Therefore, reduction cannot advance to the remaining case
30+
|
31+
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
32+
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)]
33+
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
34+
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
35+
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
36+
| and cannot be shown to be disjoint from it either.
37+
| Therefore, reduction cannot advance to the remaining case
38+
|
39+
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
40+
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
41+
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
42+
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
43+
| and cannot be shown to be disjoint from it either.
44+
| Therefore, reduction cannot advance to the remaining case
45+
|
46+
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]

tests/neg/i17944.scala

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package test {
2+
3+
import types._
4+
5+
object types {
6+
opaque type ->>[K, V] = V
7+
extension [K <: Singleton](k: K) def ->>[V](v: V): K ->> V = v.asInstanceOf[K ->> V]
8+
}
9+
10+
type FindField[T <: Tuple, K] = FindField0[T, K, 0]
11+
12+
type FindField0[T <: Tuple, K, I <: Int] <: (Any, Int) = T match {
13+
case (K ->> f) *: _ => (f, I)
14+
case _ *: t => FindField0[t, K, compiletime.ops.int.S[I]]
15+
}
16+
17+
trait Selector[T, Key, Out] {
18+
def apply(t: T): Out
19+
}
20+
21+
object Selector {
22+
inline def selectorInst[T <: Tuple, K](
23+
using idx: ValueOf[Tuple.Elem[FindField[T, K], 1]],
24+
): Selector[T, K, Tuple.Head[FindField[T, K]]] =
25+
new Selector[T, K, Tuple.Head[FindField[T, K]]] {
26+
def apply(t: T): Tuple.Head[FindField[T, K]] =
27+
val i: Int = idx.value.asInstanceOf[Int]
28+
t.productElement(i).asInstanceOf[Tuple.Head[FindField[T, K]]]
29+
}
30+
}
31+
32+
}
33+
34+
object Test {
35+
def main(args: Array[String]): Unit = {
36+
import test._
37+
import test.types._
38+
39+
val t = ("s" ->> "foo") *: ("i" ->> 3) *: EmptyTuple
40+
val s = Selector.selectorInst[("s" ->> String) *: ("i" ->> Int) *: EmptyTuple, "i"] // error
41+
val r = s(t)
42+
println(r)
43+
}
44+
}

tests/pos/i18488.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait AbstractTable[T]
2+
3+
trait Query[E, U]
4+
5+
class TableQuery[E <: AbstractTable[?]] extends Query[E, Extract[E]]
6+
7+
type Extract[E] = E match
8+
case AbstractTable[t] => t
9+
10+
trait BaseCrudRepository[E[T[_]]]:
11+
12+
type EntityTable <: AbstractTable[E[Option]]
13+
14+
def filterById: Query[EntityTable, Extract[EntityTable]] =
15+
new TableQuery[EntityTable]

0 commit comments

Comments
 (0)