Go with path-dependent types instead. Replace
trait Compiler[A] {
def mtch(o: SourceObject): Option[A]
def proceed(o: SourceObject, data: A): Unit
}
with
trait Compiler {
type A
def mtch(o: SourceObject): Option[A]
def proceed(o: SourceObject, data: A): Unit
}
and everything will work.
The trick here is that the type of data
in your for-comprehension becomes c.A
, which is the type c.proceed
expects as its second parameter.
As for null
, make compiler which don't need to pass parameters type A = Unit
, so you return Some(())
if it should proceed.