I have a trait with generic parameters which contains a method where I am attempting to define the default implementation as "empty".
trait MetaBase[T <: Throwable] {
...
def riskWithEvent[V](
vToEvaluate: => V,
failureTEvent: FailureBase[T, V] => Unit = _ => ()
): TryBase[T, V] =
...
}
I am receiving a "missing parameter type" error at the underscore right after failureTEvent: FailureBase[T, V] => Unit =. I cannot figure out how to get the Scala compiler to let go of having to know the type information at that point as it isn't used or needed.
I considered changing the parameter to:
failureTEvent: Option[FailureBase[T, V] => Unit] = None
However, I don't like that the clients must now wrap their function in a Some(). I would much prefer to allow them to not specify the parameter, or specify the parameter without a wrapper.
Any guidance on this is greatly appreciated.
Actually, it has trouble with the
Vparam.Here is
-Ylog:typer -Ytyper-debug.Or,
This works:
This doesn't:
Or just take
Any, since functions are contra-variant in the arg:Other links related to default arg typing:
https://issues.scala-lang.org/browse/SI-8884
https://issues.scala-lang.org/browse/SI-7095
Scala case class.type does not take parameters