diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt index a15ae65a4ec..f81e55ffdb6 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt @@ -106,19 +106,19 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM } private fun evaluateMemberMethodOrField(receiver: LLVMVariable, selectorName: String, scopeDepth: Int, call: PsiElement): LLVMSingleValue? { - val type = receiver.type as LLVMReferenceType - val clazz = resolveClassOrObjectLocation(type) - val field = clazz.fieldsIndex[selectorName] + if (field != null) { val result = codeBuilder.getNewVariable(field.type, pointer = 1) codeBuilder.loadClassField(result, receiver, field.offset) return result } - val methodName = clazz.structName + '.' + selectorName.substringBefore('(') + val typePath = type.location.joinToString(".") + val methodName = "${if (typePath.length > 0) "$typePath." else "" }${clazz.structName}.${selectorName.substringBefore('(')}" + val method = clazz.methods[methodName]!! val returnType = clazz.methods[methodName]!!.returnType!!.type @@ -133,7 +133,6 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM private fun resolveClassOrObjectLocation(type: LLVMReferenceType): StructCodegen { if (type.location.size == 0) { return state.classes[type.type] ?: state.objects[type.type]!! - } var codegen = state.classes[type.location[0]]!! diff --git a/translator/src/test/kotlin/tests/input/nested_classes.txt b/translator/src/test/kotlin/tests/input/nested_classes.txt index 9b8fb057177..9b1905d9c22 100644 --- a/translator/src/test/kotlin/tests/input/nested_classes.txt +++ b/translator/src/test/kotlin/tests/input/nested_classes.txt @@ -1 +1,2 @@ -nested_test_1(1) == 1 \ No newline at end of file +nested_test_1(1) == 1 +nested_test_2(1) == 1 \ No newline at end of file diff --git a/translator/src/test/kotlin/tests/kotlin/nested_classes.kt b/translator/src/test/kotlin/tests/kotlin/nested_classes.kt index b12edf58a47..b4db59b5b77 100644 --- a/translator/src/test/kotlin/tests/kotlin/nested_classes.kt +++ b/translator/src/test/kotlin/tests/kotlin/nested_classes.kt @@ -2,6 +2,10 @@ class Outer() { class Nested(var i: Int) { + + fun test(): Int { + return 1 + } } } @@ -10,4 +14,10 @@ fun nested_test_1(k: Int): Int { j.i = k return j.i +} + +fun nested_test_2(k: Int): Int { + val j = Outer.Nested(k - 1) + + return j.test() } \ No newline at end of file