dotty-feature-requests
dotty-feature-requests copied to clipboard
TupledFunction should take variance into account
I don't know the reasons for the restriction that givens for TupleFunction are only synthesized if the types are exactly same, i.e have invariant behaviour. I guess the reason is because this is for sure safe and variance can be added later on if proven to be safe as well.
I have the feeling it is safe, hence my feature request:
Consider the following:
object Main{
def main(args: Array[String]) = {
val f: Number => String = _ => "a"
val g: Integer => CharSequence = f // works as expected
var h: Tuple1[Number] => String = (_) => "b"
var i: Tuple1[Integer] => String = h // works as expected
def bar[F,G](f: F, g: G)(using tf: TupledFunction[F,G]) = ???
def [F, Args <: Tuple, R](f: F) tupled (using tf: TupledFunction[F, Args => R]): Args => R = tf.tupled(f)
h = f.tupled // works as expected
i = f.tupled // works as expected
val b = bar(f, i) // (Number => String) cannot be tupled as ((Tuple1[Integer]) => String)
bar(f, f.tupled) // works as expected, this extra step should not be needed IMO
}
}