JS: fix absence of temporary variable in secondary constructors. See KT-16377
This commit is contained in:
committed by
Alexey Andreev
parent
3b222f13f3
commit
86d1c7b7ec
+2
-1
@@ -217,13 +217,14 @@ class ClassTranslator private constructor(
|
||||
val constructorInitializer = context.getFunctionObject(constructorDescriptor)
|
||||
constructorInitializer.name = context.getInnerNameForDescriptor(constructorDescriptor)
|
||||
context.addDeclarationStatement(constructorInitializer.makeStmt())
|
||||
|
||||
context = context.contextWithScope(constructorInitializer)
|
||||
context.translateAndAliasParameters(constructorDescriptor, constructorInitializer.parameters)
|
||||
.translateFunction(constructor, constructorInitializer)
|
||||
|
||||
// Translate super/this call
|
||||
val superCallGenerators = mutableListOf<(MutableList<JsStatement>) -> Unit>()
|
||||
val referenceToClass = context.getInnerReference(classDescriptor)
|
||||
context = context.contextWithScope(constructorInitializer)
|
||||
|
||||
superCallGenerators += { it += FunctionBodyTranslator.setDefaultValueForArguments(constructorDescriptor, context) }
|
||||
|
||||
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// HAS_NO_CAPTURED_VARS: function=A_init except=Kotlin;A
|
||||
|
||||
class A() {
|
||||
var y: String? = null
|
||||
var z: Any? = null
|
||||
|
||||
constructor(x: Any) : this() {
|
||||
y = if (x == "foo") "!!!" else { z = x; ">>>" }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A("foo")
|
||||
if (a.y != "!!!") return "fail1: ${a.y}"
|
||||
if (a.z != null) return "fail2: ${a.z}"
|
||||
|
||||
val b = A(23)
|
||||
if (b.y != ">>>") return "fail3: ${b.y}"
|
||||
if (b.z != 23) return "fail4: ${b.z}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user