Возможно в этом случае вам может помочь мета-аннот...
# russian
i
Возможно в этом случае вам может помочь мета-аннотация `@DslMarker`: https://kotlinlang.org/docs/reference/whatsnew11.html#scope-control-for-implicit-receivers-in-dsls Вкратце, она разрешает использовать в скоупе только один неявный this — самый ближний.
Copy code
@DslMarker
annotation class NodeDsl

@NodeDsl
open class Node(val name: String) {
    open fun lookup() = "lookup in: $name"
}
class Example : Node("container") {
    val child1 = createChild("child1")?.apply { // with ?
        println("child1 lookup = ${lookup()}")
    }
    val child2 = createChild("child2").apply { // without ?
        println("child2 lookup = ${lookup()}")  // 'fun lookup(): String' can't be called in this context by implicit receiver. Use the explicit one if necessary
    }
    private fun createChild(name: String): Node? { // nullable
        return Node(name)
    }
}