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
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
deffoo[A, B](arr: Array[A], pf: PartialFunction[A, B]):Seq[B] = arr.toSeq.collect(pf)
deffoo[A, B](list: List[A], pf: PartialFunction[A, B]):Seq[B] = list.collect(pf) // no errors if this is commented outvalarr=Array(1, 2, 3)
valresOkay= foo(arr = arr, { case n if n %2!=0=> n.toString }) // compilesvalresNope= foo(arr = arr, pf = { case n if n %2!=0=> n.toString }) // Error 1valresNope2= foo[Int, String](arr = arr, pf = { case n if n %2!=0=> n.toString }) // Error 2
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.
The text was updated successfully, but these errors were encountered:
By the way, in Scala 2 (2.13.10), it's the third call (resNope2) which works, while the first two don't. But in this case, it works both with and without named argument.
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:
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
Scastie: https://scastie.scala-lang.org/DgUgE2wrRWmY3lzwmp30xQ
Output
Error 1:
Error 2:
Expectation
Ideally, all calls to
foo
in the code above should compile without errors.The text was updated successfully, but these errors were encountered: