I am not able to access super.message for js targe...
# javascript
l
I am not able to access super.message for js target when extending `Exception`/`Throwable` while overriding message. For reference, here is a test
Copy code
open class Parent(open val str: String) {}

class Child : Parent("Child") {
    override val str: String = "Overridden ${super.str}"
}

open class ChildEx() : Exception("ChildMsg") {
    override val message = "Overridden ${super.message}"
}

@Test
fun `test child class`() {
    println("ChildEx: ${ChildEx().message}, Child: ${Child().str}")
}
// Prints
// ChildEx: Overridden undefined, Child: Overridden Child
Shouldn't the behaviour for this be same on all targets(works fine on android/ios, in sense doesn't print undefined), is this documented somewhere or would this be considered a bug ? i tried some of the approaches by using
get()
or
lazy
but both of them run into call stack issues suggesting an infinite loop gets run due to calling message's getter instead of super, any workaround for this would be helpful.
e
Which version of Kotlin are you using?
l
2.1.20
e
Yup makes sense then, it's been fixed in 2.2.0. See KT-68775.
2.2.0 is on the right side. Note how it defines throwable properties differently compared to 2.1.20.
l
I see 😞 , i don't think we can move to 2.2.0 yet because we are blocked by our android app's kotlin version. The workaround suggested in in KT might not work for us because actual usage is little more complex than above. We have
A<-Exception
and constructs it's own message and passes on to throwable constructor itself. and
B<-A
and B's constructor arg's don't have any message at all. So we have to modify A to store message separately as well ig. Thanks for your help.
blob no problem 1