-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression tests for old issues fixed with the new match types.
- Loading branch information
Showing
4 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- [E172] Type Error: tests/neg/i17944.scala:40:87 --------------------------------------------------------------------- | ||
40 | val s = Selector.selectorInst[("s" ->> String) *: ("i" ->> Int) *: EmptyTuple, "i"] // error | ||
| ^ | ||
|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. | ||
| | ||
|Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce Tuple.Elem[test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)], (1 : Int)] | ||
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)] | ||
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)] | ||
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int) | ||
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int)) | ||
| and cannot be shown to be disjoint from it either. | ||
| Therefore, reduction cannot advance to the remaining case | ||
| | ||
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]] | ||
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)] | ||
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)] | ||
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int) | ||
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int)) | ||
| and cannot be shown to be disjoint from it either. | ||
| Therefore, reduction cannot advance to the remaining case | ||
| | ||
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]] | ||
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)] | ||
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int) | ||
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int)) | ||
| and cannot be shown to be disjoint from it either. | ||
| Therefore, reduction cannot advance to the remaining case | ||
| | ||
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]] | ||
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)] | ||
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)] | ||
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int) | ||
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int)) | ||
| and cannot be shown to be disjoint from it either. | ||
| Therefore, reduction cannot advance to the remaining case | ||
| | ||
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]] | ||
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)] | ||
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int) | ||
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int)) | ||
| and cannot be shown to be disjoint from it either. | ||
| Therefore, reduction cannot advance to the remaining case | ||
| | ||
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package test { | ||
|
||
import types._ | ||
|
||
object types { | ||
opaque type ->>[K, V] = V | ||
extension [K <: Singleton](k: K) def ->>[V](v: V): K ->> V = v.asInstanceOf[K ->> V] | ||
} | ||
|
||
type FindField[T <: Tuple, K] = FindField0[T, K, 0] | ||
|
||
type FindField0[T <: Tuple, K, I <: Int] <: (Any, Int) = T match { | ||
case (K ->> f) *: _ => (f, I) | ||
case _ *: t => FindField0[t, K, compiletime.ops.int.S[I]] | ||
} | ||
|
||
trait Selector[T, Key, Out] { | ||
def apply(t: T): Out | ||
} | ||
|
||
object Selector { | ||
inline def selectorInst[T <: Tuple, K]( | ||
using idx: ValueOf[Tuple.Elem[FindField[T, K], 1]], | ||
): Selector[T, K, Tuple.Head[FindField[T, K]]] = | ||
new Selector[T, K, Tuple.Head[FindField[T, K]]] { | ||
def apply(t: T): Tuple.Head[FindField[T, K]] = | ||
val i: Int = idx.value.asInstanceOf[Int] | ||
t.productElement(i).asInstanceOf[Tuple.Head[FindField[T, K]]] | ||
} | ||
} | ||
|
||
} | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
import test._ | ||
import test.types._ | ||
|
||
val t = ("s" ->> "foo") *: ("i" ->> 3) *: EmptyTuple | ||
val s = Selector.selectorInst[("s" ->> String) *: ("i" ->> Int) *: EmptyTuple, "i"] // error | ||
val r = s(t) | ||
println(r) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
trait AbstractTable[T] | ||
|
||
trait Query[E, U] | ||
|
||
class TableQuery[E <: AbstractTable[?]] extends Query[E, Extract[E]] | ||
|
||
type Extract[E] = E match | ||
case AbstractTable[t] => t | ||
|
||
trait BaseCrudRepository[E[T[_]]]: | ||
|
||
type EntityTable <: AbstractTable[E[Option]] | ||
|
||
def filterById: Query[EntityTable, Extract[EntityTable]] = | ||
new TableQuery[EntityTable] |