[JS IR BE] Fix setting names of Throwable subclasses without primary constructor

This commit is contained in:
Svyatoslav Kuzmich
2019-07-03 14:35:09 +03:00
parent 918d470e1b
commit 871180cdc0
2 changed files with 11 additions and 5 deletions
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.ir.backend.js.lower package org.jetbrains.kotlin.ir.backend.js.lower
import org.jetbrains.kotlin.backend.common.FileLoweringPass 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.IrStatement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext 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 { override fun visitConstructor(declaration: IrConstructor, data: IrDeclarationParent): IrStatement {
declaration.transformChildren(this, data)
if (!declaration.isPrimary) return declaration
val klass = data as IrClass val klass = data as IrClass
if (klass.defaultType.isThrowableTypeOrSubtype()) { if (klass.defaultType.isThrowableTypeOrSubtype() && declaration.callsSuper(context.irBuiltIns)) {
(declaration.body as? IrBlockBody)?.let { (declaration.body as? IrBlockBody)?.let {
it.statements += JsIrBuilder.buildCall(propertySetter, unitType).apply { it.statements += JsIrBuilder.buildCall(propertySetter, unitType).apply {
putValueArgument(0, JsIrBuilder.buildGetValue(klass.thisReceiver!!.symbol)) putValueArgument(0, JsIrBuilder.buildGetValue(klass.thisReceiver!!.symbol))
@@ -97,6 +94,8 @@ class ThrowableLowering(val context: JsIrBackendContext) : FileLoweringPass {
} }
} }
declaration.transformChildren(this, data)
return declaration return declaration
} }
@@ -3,6 +3,11 @@ 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)
class MyException3: Throwable {
constructor(m: String? = null) : super(m) {}
}
// TODO: add direct inheritors of Throwable: // TODO: add direct inheritors of Throwable:
// - with cause only, in the primary constructor // - with cause only, in the primary constructor
@@ -30,6 +35,8 @@ fun box(): String {
check(MyException("aaa"), "MyException: aaa") check(MyException("aaa"), "MyException: aaa")
check(MyException2(), "MyException2: null") check(MyException2(), "MyException2: null")
check(MyException2("aaa"), "MyException2: aaa") check(MyException2("aaa"), "MyException2: aaa")
check(MyException3(), "MyException3: null")
check(MyException3("aaa"), "MyException3: aaa")
return "OK" return "OK"
} }