I am testing if a tuple’s members have all the same type. Below the code shows how Tuple.Union
can be used when we test against an instance. However, when I attempt to use this in a function’s parameter I get a compilation error (see the end of this post). I am using Scala 3.1.0. What am I doing wrong?
EDIT: same result with 3.1.1
Code can be found in scastie
TIA
val t1 = ( 1, 2L, 3.0f, 4.0, "five", '6' )
val csv = ("1", "2", "3.0", "4.0", "\"five\"", "'6'" )
summon[Tuple.Union[csv.type] =:= String]
def toCSVString[T<: Tuple](separator: String)(t:T): String =
summon[Tuple.Union[t.type] =:= String]
???
Compilation error:
error] -- Error: /home/hmf/VSCodeProjects/aiops/utils/test/src/TimeSeriesSpec.scala:622:44
[error] 622 | summon[Tuple.Union[t.type] =:= String]
[error] | ^
[error] |Cannot prove that Tuple.Union[(t : T)]
[error] |
[error] |where: T is a type in method toCSVString with bounds <: Tuple
[error] | =:= String.
[error] |
[error] |Note: a match type could not be fully reduced:
[error] |
[error] | trying to reduce Tuple.Union[(t : T)]
[error] | trying to reduce scala.Tuple.Fold[(t : T), Nothing, [x, y] =>> x | y]
[error] | failed since selector (t : T)
[error] | does not match case EmptyTuple => Nothing
[error] | and cannot be shown to be disjoint from it either.
[error] | Therefore, reduction cannot advance to the remaining case
[error] |
[error] | case h *: t => h | scala.Tuple.Fold[t, Nothing, [x, y] =>> x | y]
[error] one error found
[error] one error found