You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importcompiletime.ops.int._importcompiletime.constValuetypeElem[X<:Tuple, N<:Int] =Xmatchcase x *: xs =>Nmatchcase0=> x
caseS[k] =>Elem[xs, k]
inlinedefelem[X<:Tuple, N<:Int](x: X, n: N) :Elem[X, N] = x matchcase (h *: t): (x *: _) =>inline n matchcase_: 0=> h
case_: S[k] => elem(t, constValue[k])
Output
[error] 37|case_: 0=> h
[error] | ^
[error] |Found: (h : x)
[error] |Required:Nmatch {
[error] |case (0:Int) => x
[error] |case compiletime.ops.int.S[k] =>Elem[_, k]
[error] | }
[error] |
[error] |where: N is a typein method elem with bounds <:Int
[error] | _ is a typein method elem with bounds <:Tuple
[error] | x is a typein method elem with bounds
[error] |
[error] | longer explanation available when compiling with`-explain`
[error] -- [E007] TypeMismatchError: .../src/main/scala/Part3.scala:38:26
[error] 38|case_: S[k] => elem(t, constValue[k])
[error] | ^^^^^^^^^^^^^^^^^^^^^^
[error] |Found:Elem[_, k]
[error] |Required:Nmatch {
[error] |case (0:Int) => x
[error] |case compiletime.ops.int.S[k²] =>Elem[_, k²]
[error] | }
[error] |
[error] |where: N is a typein method elem with bounds <:Int
[error] | _ is a typein method elem with bounds <:Tuple
[error] | k is a typein method elem with bounds <:Int
[error] | k² is a typevariablewith constraint <:Int
[error] | x is a typein method elem with bounds
[error] |
[error] |
[error] |Note: a matchtypecould not be fully reduced:
[error] |
[error] | trying to reduce Elem[_, k]
[error] | failed since selector _
[error] | does not matchcase x *: xs => k match {
[error] |case (0:Int) => x
[error] |case compiletime.ops.int.S[k] =>Elem[xs, k]
[error] | }
[error] | and cannot be shown to be disjoint from it either.
[error] |
[error] | longer explanation available when compiling with`-explain`
Expectation
The code should compile.
The text was updated successfully, but these errors were encountered:
This compiles in Scala 3.3, but emits the following warning:
Compiling project (Scala 3.3.0, JVM)
[warn] ./sync.scala:11:16
[warn] Type ascriptions after patterns other than:
[warn] * variable pattern, e.g. `case x: String =>`
[warn] * number literal pattern, e.g. `case 10.5: Double =>`
[warn] are no longer supported. Remove the type ascription or move it to a separate variable pattern.
[warn] case (h *: t): (x *: _) =>
[warn] ^
[warn] ./sync.scala:10:66
[warn] match may not be exhaustive.
[warn]
[warn] It would fail on pattern case: EmptyTuple
[warn] inline def elem[X <: Tuple, N <: Int](x: X, n: N) : Elem[X, N] = x match
[warn]
Compiler version
3.2
Minimized code
Output
Expectation
The code should compile.
The text was updated successfully, but these errors were encountered: