The following code doesn't compile:
def f[T](conv: Option[String => T]) {}
f(Some(_.toInt))
with <console>:13: error: missing parameter type for expanded function ((x$1) => x$1.toInt)
Of course, explicit type makes it fine:
scala> f(Some((x: String) => x.toInt))
Why the compiler can't infer String type here? Is there some kind of ambiguity?
In general, is it possible to check and examine manually the generated code from underscore expansion?
String
then it maybe would be able to infer it in some cases but otherwise you could just pass someClassWithoutToInt
and it cannot infer it with underscore, - sebszyllerf(_.toInt) // show
in REPL or-Xprint:typer
to see how typer sees your code. - som-snytt