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
importscala.compiletime.ops.int.*typeAnyInt[A<:Int] <:Int=Amatch {
case _ =>A
}
typeIndexOf[A, T<:Tuple] <:Int=Tmatch {
caseEmptyTuple=>-1caseA*: t =>0case _ *: t =>IndexOf[A, t] match {
case-1=>-1caseAnyInt[a] =>S[a]
}
}
opaquetypeIndexes[A, T<:Tuple] =List[Int]
objectIndexes {
extension [S, T<:Tuple](s: Indexes[S, T]) inlinedeftoList:List[Int] = s
inlinegivenof[A, T<:Tuple](usingIndexOf[A, T] >=0=:=true)(usingindex: ValueOf[IndexOf[A, T]],
next: Indexes[A, Tuple.Drop[T, S[IndexOf[A, T]]]]
):Indexes[A, T] = index.value :: next
inlinegivenempty[A, T<:Tuple](usingIndexOf[A, T] =:=-1):Indexes[A, T] =Nil
}
traitGetAll[A] {
defapply[T<:Tuple](t: T)(usingindexes: Indexes[A, T]):List[A] =
indexes.toList.map(i => t.asInstanceOf[NonEmptyTuple](i).asInstanceOf[A])
}
privateobjectGetAllInstanceextendsGetAll[Nothing]
defgetAll[A]:GetAll[A] =GetAllInstance.asInstanceOf[GetAll[A]]
// the code here is trying to get all values from a tuple that has type [X] as a list// this works if there are only two strings in the tuple
getAll[String](("str1", 1, "str2", false))
//but this not compiles if there are more than two strings in the tuple
getAll[String](("str1", 1, "str2", false, "str3"))
Output
The compiler error for the code getAll[String](("str1", 1, "str2", false, "str3"))
importscala.compiletime.ops.int.*typeAnyInt[A<:Int] <:Int=Amatch {
case _ =>A
}
typeIndexOf[A, T<:Tuple] <:Int=Tmatch {
caseEmptyTuple=>-1caseA*: t =>0case _ *: t =>IndexOf[A, t] match {
case-1=>-1caseAnyInt[a] =>S[a]
}
}
typeIndexes[A, T<:Tuple]
objectIndexes {
givenof[A, T<:Tuple](usingIndexOf[A, T] >=0=:=true)(usingindex: ValueOf[IndexOf[A, T]],
next: Indexes[A, Tuple.Drop[T, S[IndexOf[A, T]]]]
):Indexes[A, T] =???givenempty[A, T<:Tuple](usingIndexOf[A, T] =:=-1):Indexes[A, T] =???
}
classGetAll[A]:defapply[T<:Tuple](t: T)(usingindexes: Indexes[A, T]):List[A] =???defgetAll[A]:GetAll[A] =newGetAll[A]
deftest=// the code here is trying to get all values from a tuple that has type [X] as a list// this works if there are only two strings in the tuple
getAll[String](("str1", 1, "str2", false))
//but this not compiles if there are more than two strings in the tuple
getAll[String](("str1", 1, "str2", false, "str3"))
Compiler version
3.3.0
Minimized code
Output
The compiler error for the code
getAll[String](("str1", 1, "str2", false, "str3"))
Expectation
for the error here
the compiler should call
tupleops.Indexes.of
, nottupleops.Indexes.empty
The text was updated successfully, but these errors were encountered: