Closed
Description
I have an overloaded method that takes a partial function as an argument.
Compilation fails if I specify the name of the argument when I call the method.
Two different errors in fact:
- that I'm missing parameter types if I don't give them, and
- that a total function was found instead of a partial one, if I do.
Compilation works if I remove the name of the argument or if I remove the unused overloaded method.
Compiler version
3.2.2 and 3.3.0-RC3
Minimized code
def foo[A, B](arr: Array[A], pf: PartialFunction[A, B]): Seq[B] = arr.toSeq.collect(pf)
def foo[A, B](list: List[A], pf: PartialFunction[A, B]): Seq[B] = list.collect(pf) // no errors if this is commented out
val arr = Array(1, 2, 3)
val resOkay = foo(arr = arr, { case n if n % 2 != 0 => n.toString }) // compiles
val resNope = foo(arr = arr, pf = { case n if n % 2 != 0 => n.toString }) // Error 1
val resNope2 = foo[Int, String](arr = arr, pf = { case n if n % 2 != 0 => n.toString }) // Error 2
Scastie: https://scastie.scala-lang.org/DgUgE2wrRWmY3lzwmp30xQ
Output
Error 1:
Missing parameter type
I could not infer the type of the parameter x$1 of expanded function:
x$1 =>
x$1 match
{
case n if n % 2 != 0 =>
n.toString
}.
val resNope = foo(arr = arr, pf = { case n if n % 2 != 0 => n.toString }) // error
Error 2:
Found: Int => String
Required: PartialFunction[Int, String]
Expectation
Ideally, all calls to foo
in the code above should compile without errors.