Here is a very condensed version:
case class Brickwall[A](otherSide: A)
trait Monoman { def me(m: this.type): Unit }
def test(m: Monoman): Unit = m.me(Brickwall(m).otherSide)
-> error: type mismatch;
found : Monoman
required: m.type
stupid brickwall doesn't let me through. any ideas how it might be possible? secret scala tunnel effects? hoping...
As far as I know the Scala compiler refuses to infer path dependent types, so a little type annotation helps:
def test( m: Monoman ) { m.me( Brickwall[m.type]( m ).otherSide )}
Yes, singleton types are never inferred by the Scala compiler.
One possibility is to add a factory method to the Monoman trait:
trait Monoman {
def me( m: this.type ) : Unit
def createWall = Brickwall[this.type](this)
}
def test( m: Monoman ) { m.me(m.createWall.otherSide) }
Maybe that's not a viable solution in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With