https://kotlinlang.org logo
Title
s

spand

02/15/2018, 12:55 PM
I have the following code that fails with the error shown below. How can I get more explicit than I already am ?
interface Tooltipable : FlowContent {
    fun Tag.withTooltip(block: FlowContent.() -> Unit)
    fun Tag.tooltipBox(content: FlowContent.() -> Unit) {
        (this@tooltipBox).withTooltip{
            div(classes = "tooltip-box",block = content)
        }
    }
}
Error:(11, 9) Kotlin: 'fun Tag.withTooltip(block: FlowContent.() -> Unit): Unit' can't be called in this context by implicit receiver. Use the explicit one if necessary
Ok, this seems to work:
interface Tooltipable : FlowContent {
    fun Tag.withTooltip(block: FlowContent.() -> Unit)
    fun Tag.tooltipBox(content: FlowContent.() -> Unit) {
        with(this@Tooltipable) {
            this@tooltipBox.withTooltip {
                div(classes = "tooltip-box",block = content)
            }
        }
    }
}
u

540grunkspin

02/15/2018, 1:10 PM
Do you need the this@tooltipBox if you use it with with with statement?
I was thinking that this@Tooltipable.withToolTip would work