JS: fix scope of function generated for primary constructor. See KT-15678

This commit is contained in:
Alexey Andreev
2017-01-16 12:22:52 +03:00
parent daac24b62e
commit a927770935
5 changed files with 35 additions and 6 deletions
@@ -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"
}