[JS IR BE] Fix setting names of Throwable subclasses without primary constructor
This commit is contained in:
+4
-5
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower.callsSuper
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
@@ -82,12 +83,8 @@ class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
||||
}
|
||||
|
||||
override fun visitConstructor(declaration: IrConstructor, data: IrDeclarationParent): IrStatement {
|
||||
declaration.transformChildren(this, data)
|
||||
|
||||
if (!declaration.isPrimary) return declaration
|
||||
|
||||
val klass = data as IrClass
|
||||
if (klass.defaultType.isThrowableTypeOrSubtype()) {
|
||||
if (klass.defaultType.isThrowableTypeOrSubtype() && declaration.callsSuper(context.irBuiltIns)) {
|
||||
(declaration.body as? IrBlockBody)?.let {
|
||||
it.statements += JsIrBuilder.buildCall(propertySetter, unitType).apply {
|
||||
putValueArgument(0, JsIrBuilder.buildGetValue(klass.thisReceiver!!.symbol))
|
||||
@@ -97,6 +94,8 @@ class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
||||
}
|
||||
}
|
||||
|
||||
declaration.transformChildren(this, data)
|
||||
|
||||
return declaration
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,11 @@ package foo
|
||||
|
||||
class MyException(m: String? = null): Exception(m)
|
||||
class MyException2(m: String? = null): Throwable(m)
|
||||
|
||||
class MyException3: Throwable {
|
||||
constructor(m: String? = null) : super(m) {}
|
||||
}
|
||||
|
||||
// TODO: add direct inheritors of Throwable:
|
||||
// - with cause only, in the primary constructor
|
||||
|
||||
@@ -30,6 +35,8 @@ fun box(): String {
|
||||
check(MyException("aaa"), "MyException: aaa")
|
||||
check(MyException2(), "MyException2: null")
|
||||
check(MyException2("aaa"), "MyException2: aaa")
|
||||
check(MyException3(), "MyException3: null")
|
||||
check(MyException3("aaa"), "MyException3: aaa")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user