https://kotlinlang.org logo
Title
g

groostav

03/06/2017, 6:28 AM
is it intended behavior that
fun ParseNode.accept(visitor: Visitor){
    when(this){
        is NodeTypeA -> this.internalAccept(visitor::visitEnter, visitor::visitLeave)
    }
}

private fun <T> T.internalAccept(enter: (T) -> Unit, leave: (T) -> Unit): Unit = TODO()
will not compile without the
this.
infront of
internalAccept
? It seems like theres a corner case I'm hitting between smart casting and type inference that isnt covered here.
a

Andreas Sinz

03/06/2017, 8:50 AM
groostav: What error message do you get when trying to compile it?
g

groostav

03/06/2017, 7:47 PM
if you remove the
this.
from the third line, then
Error:(31, 50) Kotlin: None of the following functions can be called with the arguments supplied:
public final fun visitEnter(node: NodeTypeA): Unit defined in com.empowerops.Visitor
public final fun visitEnter(node: NodeTypeB): Unit defined in com.empowerops.Visitor
and so on