JS: fix scope of function generated for primary constructor. See KT-15678
This commit is contained in:
+2
-1
@@ -75,7 +75,8 @@ class ClassTranslator private constructor(
|
||||
val scope = context().getScopeForDescriptor(descriptor)
|
||||
val context = context().newDeclaration(descriptor)
|
||||
|
||||
val constructorFunction = context.createRootScopedFunction(descriptor)
|
||||
val constructorFunction = descriptor.unsubstitutedPrimaryConstructor?.let { context.getFunctionObject(it) } ?:
|
||||
context.createRootScopedFunction(descriptor)
|
||||
constructorFunction.name = context.getInnerNameForDescriptor(descriptor)
|
||||
context.addDeclarationStatement(constructorFunction.makeStmt())
|
||||
val enumInitFunction = if (descriptor.kind == ClassKind.ENUM_CLASS) createEnumInitFunction() else null
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
var log = ""
|
||||
|
||||
inline fun f(x: Int): Int {
|
||||
val result = x * 2
|
||||
log += "f($x)"
|
||||
return result
|
||||
}
|
||||
|
||||
fun bar() = 10
|
||||
|
||||
class Test {
|
||||
val value: Int
|
||||
|
||||
init {
|
||||
val x = 3
|
||||
val y = f(bar())
|
||||
value = x + y
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = Test()
|
||||
if (test.value != 23) return "fail: ${test.value}"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user