diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt index bb3e7ee6025..8736c81aadf 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt @@ -5,6 +5,8 @@ import com.intellij.psi.PsiWhiteSpace import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.psi.tree.IElementType import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor +import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments @@ -13,6 +15,7 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getType import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant +import org.kotlinnative.translator.exceptions.UnimplementedException import org.kotlinnative.translator.llvm.* import org.kotlinnative.translator.llvm.types.* import java.util.* @@ -285,7 +288,17 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM expr is KtArrayAccessExpression -> evaluateArrayAccessExpression(expr, scopeDepth + 1) isEnumClassField(expr) -> resolveEnumClassField(expr) (expr is KtNameReferenceExpression) && (classScope != null) -> evaluateNameReferenceExpression(expr, classScope) - else -> variableManager.get(expr.firstChild.text) + else -> { + val referenceContext = state.bindingContext.get(BindingContext.REFERENCE_TARGET, expr) + when (referenceContext) { + is PropertyDescriptorImpl -> { + val receiverThis = variableManager.get("this")!! + evaluateMemberMethodOrField(receiverThis, expr.firstChild.text, topLevel, call = null)!! + } + else -> variableManager.get(expr.firstChild.text) + } + + } } private fun resolveEnumClassField(expr: KtReferenceExpression): LLVMSingleValue { diff --git a/translator/src/test/kotlin/tests/input/this_test_1.txt b/translator/src/test/kotlin/tests/input/this_test_1.txt new file mode 100644 index 00000000000..dd4d81be586 --- /dev/null +++ b/translator/src/test/kotlin/tests/input/this_test_1.txt @@ -0,0 +1 @@ +this_test_1_Int(48) == 53 diff --git a/translator/src/test/kotlin/tests/kotlin/this_test_1.kt b/translator/src/test/kotlin/tests/kotlin/this_test_1.kt new file mode 100644 index 00000000000..6471202d711 --- /dev/null +++ b/translator/src/test/kotlin/tests/kotlin/this_test_1.kt @@ -0,0 +1,12 @@ +class this_test_1_class { + var data: Int = 5 + fun f(x: Int) { + data = x + 5 + } +} + +fun this_test_1(arg: Int): Int { + val instance = this_test_1_class() + instance.f(arg) + return instance.data +} \ No newline at end of file