Skip to content

Commit d54fd9e

Browse files
committed
Add regression tests for old issues fixed with the new match types.
1 parent cb94367 commit d54fd9e

File tree

4 files changed

+105
-10
lines changed

4 files changed

+105
-10
lines changed

tests/neg/i17944.check

Lines changed: 46 additions & 0 deletions
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

Lines changed: 44 additions & 0 deletions
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/neg/i18171.scala

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

tests/pos/i18488.scala

Lines changed: 15 additions & 0 deletions
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)