Kotlin feature request

or if this is the existing feature

I’m not exactly the name of such method (Note that it is not extension method, it reside with in a class)

override fun Canvas.onDrawWithMatrix() {
    val staticLayout = staticLayoutVO.value ?: return
    if (top != -1f && left != -1f) {
        translate(left, top)
        staticLayout.draw(this)
    }
}

is there way to call super method?

example being:

It even shows you the syntax in the popup.

override fun foo() {
    super.foo()
    // some other code
}

the function is

override fun Canvas.onDrawWithMatrix() {
val staticLayout = staticLayoutVO.value ?: return
if (top != -1f && left != -1f) {
    translate(left, top)
    staticLayout.draw(this)
}

}

it’s different than normal ones

I also looked the decompiled java code

super.onDraw(this) doesn’t work?

It won’t work since this method was called from that one so it will end up an infinite loop

Is this an API under your control? Why do you use an extension function here? What do you want to accomplish that wouldn’t be possible without extension functions?

There was a related topic in this forum.

Somethings not right here. You shouldn’t be able to override a function you can’t call. That’s simply not how the JVM works. I guess that your intelli-sense is not working.
Try to use super.onDrawWithMatrix() and if this does not work, maybe post the compiler error.
Also just out of curiosity, what editor are you using?

As @medium pointed out, you can’t call superclass implementation of overridden extension functions as I found out 3 years ago. Please upvote the bug tracking this: https://youtrack.jetbrains.com/issue/KT-11488

the way to call it is canvas.onDrawWithMatrix() however it can only be called from within the super class.

(as you can see from the right section of the second screenshot)

Since you don’t want to post the compiler error, I’ll do it for you :wink:. I reproduced your problem

Error:(9, 9) Kotlin: Abstract member cannot be accessed directly

This should explain why you can’t and wont ever be able to call super.onDrawWithMatrix()

i don’t mind sharing my code it’s just I’ve already changed the related code and can’t be bothered.

your error indicates that the super method you are trying override is abstract, and it’s not my case at all.

btw I’m using latest android studio canary

https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS4zLjIxIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsImpzQ29kZSI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJmb2xkZWRCdXR0b24iOnRydWUsInJlYWRPbmx5IjpmYWxzZSwiY29kZSI6Ii8qKlxuICogWW91IGNhbiBlZGl0LCBydW4sIGFuZCBzaGFyZSB0aGlzIGNvZGUuIFxuICogcGxheS5rb3RsaW5sYW5nLm9yZyBcbiAqL1xuXG5cbmZ1biBtYWluKGFyZ3M6IEFycmF5PFN0cmluZz4pIHtcblx0dmFsIGIgPSBCKClcbiAgICBiLmNhbGxtZSgpXG59XG5cbm9wZW4gY2xhc3MgQSB7XG4gICAgZnVuIGNhbGxtZSgpIHtcbiAgICAgICAgdmFsIHN0ciA9IFwic2FtcGxlIFwiXG4gICAgICAgIHZhbCByZXN1bHQgPSBzdHIuY29uY2F0ZSgpXG4gICAgICAgIHByaW50bG4ocmVzdWx0KVxuICAgIH1cbiAgICBcbiAgICAvLyBAQ2FsbFN1cGVyIFxuICAgIG9wZW4gZnVuIFN0cmluZy5jb25jYXRlKCkgOiBTdHJpbmcge1xuICAgICAgICByZXR1cm4gdGhpcyArIFwiZnJvbUEgXCJcbiAgICB9XG4gICAgXG59XG5cbm9wZW4gY2xhc3MgQiA6IEEoKXtcbiAgICBvdmVycmlkZSBmdW4gU3RyaW5nLmNvbmNhdGUoKSA6IFN0cmluZyB7XG4gICAgICAgIC8vIG5lZWQgKGJ1dCBubyB3YXkpIHRvIGNhbGwgc3VwZXIgaGVyZVxuICAgICAgICBzdXBlci5jb25jYXRlKClcbiAgICAgICAgcmV0dXJuIHRoaXMgKyBcImZyb21CIFwiXG4gICAgfVxufSJ9

ofcourse, not where you are looking for, but if you have java7, you can temporarily use this workaround:

override fun String.concate() : String {
    return MethodHandles.lookup().findSpecial(
        A::class.java, "concate",
        MethodType.methodType(String::class.java, String::class.java),
        this@B::class.java
    ).invokeWithArguments(this@B, this) as String
}