diff --git a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt index 806c2b6cabd..23134e9f12c 100644 --- a/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt +++ b/translator/src/main/kotlin/org/kotlinnative/translator/BlockCodegen.kt @@ -294,7 +294,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM val expression = explicitReceiver.expression as KtReferenceExpression val receiver = evaluateReferenceExpression(expression, scope)!! as LLVMVariable - val pureReceiver = loadArgumentIfRequired(receiver, LLVMVariable("", receiver.type, pointer = 1)) + val pureReceiver = downLoadArgument(receiver, 1) val targetClassName = (receiver.type as LLVMReferenceType).type @@ -466,6 +466,9 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM return result } + private fun downLoadArgument(value: LLVMSingleValue, pointer: Int): LLVMSingleValue = + loadArgumentIfRequired(value, LLVMVariable("", value.type!!, pointer = pointer)) + private fun loadArgsIfRequired(names: List, args: List) = names.mapIndexed(fun(i: Int, value: LLVMSingleValue): LLVMSingleValue { return loadArgumentIfRequired(value, args[i]) @@ -778,11 +781,12 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM private fun evaluateIfOperator(element: KtIfExpression, scopeDepth: Int, isExpression: Boolean = true): LLVMVariable? { val conditionResult = evaluateExpression(element.condition, scopeDepth)!! + val conditionNativeResult = downLoadArgument(conditionResult, 0) return if (isExpression) - executeIfExpression(conditionResult, element.then!!, element.`else`, element, scopeDepth + 1) + executeIfExpression(conditionNativeResult, element.then!!, element.`else`, element, scopeDepth + 1) else - executeIfBlock(conditionResult, element.then!!, element.`else`, scopeDepth + 1) + executeIfBlock(conditionNativeResult, element.then!!, element.`else`, scopeDepth + 1) } private fun executeIfExpression(conditionResult: LLVMSingleValue, thenExpression: KtExpression, elseExpression: PsiElement?, ifExpression: KtIfExpression, scopeDepth: Int): LLVMVariable? { diff --git a/translator/src/test/kotlin/tests/input/if_boolean_argument_1.txt b/translator/src/test/kotlin/tests/input/if_boolean_argument_1.txt new file mode 100644 index 00000000000..ac65c173312 --- /dev/null +++ b/translator/src/test/kotlin/tests/input/if_boolean_argument_1.txt @@ -0,0 +1,2 @@ +if_boolean_argument_1_Boolean(1) == 11 +if_boolean_argument_1_Boolean(0) == 411 diff --git a/translator/src/test/kotlin/tests/kotlin/if_boolean_argument_1.kt b/translator/src/test/kotlin/tests/kotlin/if_boolean_argument_1.kt new file mode 100644 index 00000000000..3d0dc982a00 --- /dev/null +++ b/translator/src/test/kotlin/tests/kotlin/if_boolean_argument_1.kt @@ -0,0 +1,3 @@ +fun if_boolean_argument_1(value: Boolean): Int { + return if (value) 11 else 411 +} \ No newline at end of file