[JS BE] KT-22053 Fix constructor delegation of immediate subtype of Error
This commit is contained in:
+5
@@ -3004,6 +3004,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/expression/try/exceptionToString.kt");
|
runTest("js/js.translator/testData/box/expression/try/exceptionToString.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22053.kt")
|
||||||
|
public void testKt22053() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/expression/try/kt22053.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multipleCatchBlocks.kt")
|
@TestMetadata("multipleCatchBlocks.kt")
|
||||||
public void testMultipleCatchBlocks() throws Exception {
|
public void testMultipleCatchBlocks() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/expression/try/multipleCatchBlocks.kt");
|
runTest("js/js.translator/testData/box/expression/try/multipleCatchBlocks.kt");
|
||||||
|
|||||||
+5
@@ -3004,6 +3004,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
|||||||
runTest("js/js.translator/testData/box/expression/try/exceptionToString.kt");
|
runTest("js/js.translator/testData/box/expression/try/exceptionToString.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22053.kt")
|
||||||
|
public void testKt22053() throws Exception {
|
||||||
|
runTest("js/js.translator/testData/box/expression/try/kt22053.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("multipleCatchBlocks.kt")
|
@TestMetadata("multipleCatchBlocks.kt")
|
||||||
public void testMultipleCatchBlocks() throws Exception {
|
public void testMultipleCatchBlocks() throws Exception {
|
||||||
runTest("js/js.translator/testData/box/expression/try/multipleCatchBlocks.kt");
|
runTest("js/js.translator/testData/box/expression/try/multipleCatchBlocks.kt");
|
||||||
|
|||||||
+3
-1
@@ -291,7 +291,9 @@ class ClassTranslator private constructor(
|
|||||||
val delegationClassDescriptor = (resolvedCall?.resultingDescriptor as? ClassConstructorDescriptor)?.constructedClass
|
val delegationClassDescriptor = (resolvedCall?.resultingDescriptor as? ClassConstructorDescriptor)?.constructedClass
|
||||||
|
|
||||||
if (resolvedCall != null && !KotlinBuiltIns.isAny(delegationClassDescriptor!!)) {
|
if (resolvedCall != null && !KotlinBuiltIns.isAny(delegationClassDescriptor!!)) {
|
||||||
if (JsDescriptorUtils.isImmediateSubtypeOfError(classDescriptor)) {
|
val isDelegationToCurrentClass = delegationClassDescriptor == classDescriptor
|
||||||
|
val isDelegationToErrorClass = JsDescriptorUtils.isImmediateSubtypeOfError(classDescriptor) && !isDelegationToCurrentClass
|
||||||
|
if (isDelegationToErrorClass) {
|
||||||
superCallGenerators += {
|
superCallGenerators += {
|
||||||
val innerContext = context().innerBlock()
|
val innerContext = context().innerBlock()
|
||||||
ClassInitializerTranslator.emulateSuperCallToNativeError(
|
ClassInitializerTranslator.emulateSuperCallToNativeError(
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package foo
|
|||||||
class MyException(m: String? = null): Exception(m)
|
class MyException(m: String? = null): Exception(m)
|
||||||
class MyException2(m: String? = null): Throwable(m)
|
class MyException2(m: String? = null): Throwable(m)
|
||||||
// TODO: add direct inheritors of Throwable:
|
// TODO: add direct inheritors of Throwable:
|
||||||
// - with secondary constructors
|
|
||||||
// - with cause only, in the primary constructor
|
// - with cause only, in the primary constructor
|
||||||
|
|
||||||
fun check(e: Throwable, expectedString: String) {
|
fun check(e: Throwable, expectedString: String) {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
// EXPECTED_REACHABLE_NODES: 1126
|
||||||
|
package foo
|
||||||
|
|
||||||
|
class MyThrowable(message: String?) : Throwable("through primary: " + message) {
|
||||||
|
public var initOrder = ""
|
||||||
|
|
||||||
|
constructor() : this(message = "secondary") {
|
||||||
|
initOrder += "2"
|
||||||
|
}
|
||||||
|
constructor(i: Int) : this() {
|
||||||
|
initOrder += "3"
|
||||||
|
}
|
||||||
|
|
||||||
|
init { initOrder += "1" }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val mt1 = MyThrowable("primary")
|
||||||
|
assertEquals(mt1.toString(), "MyThrowable: through primary: primary")
|
||||||
|
assertEquals(mt1.initOrder, "1")
|
||||||
|
|
||||||
|
val mt2 = MyThrowable()
|
||||||
|
assertEquals(mt2.toString(), "MyThrowable: through primary: secondary")
|
||||||
|
assertEquals(mt2.initOrder, "12")
|
||||||
|
|
||||||
|
val mt3 = MyThrowable(1)
|
||||||
|
assertEquals(mt3.toString(), "MyThrowable: through primary: secondary")
|
||||||
|
assertEquals(mt3.initOrder, "123")
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user