diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/KotlinUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/KotlinUtils.kt index beeddadcafe..51e59331963 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/KotlinUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/KotlinUtils.kt @@ -48,10 +48,8 @@ fun KtElement.deparenthesize(): KtElement = fun ResolvedCall<*>.isValueArgumentReorderingRequired(): Boolean { var lastValueParameterIndex = -1 for (valueArgument in call.valueArguments) { - val argumentMapping = getArgumentMapping(valueArgument) - if (argumentMapping !is ArgumentMatch || argumentMapping.isError()) { - throw Exception("Value argument in function call is mapped with error") - } + val argumentMapping = getArgumentMapping(valueArgument) as? ArgumentMatch ?: + throw Exception("Value argument in function call is mapped with error") val argumentIndex = argumentMapping.valueParameter.index if (argumentIndex < lastValueParameterIndex) { return true diff --git a/compiler/testData/ir/irText/expressions/argumentMappedWithError.kt b/compiler/testData/ir/irText/expressions/argumentMappedWithError.kt new file mode 100644 index 00000000000..560788252c6 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/argumentMappedWithError.kt @@ -0,0 +1,9 @@ +fun Number.convert(): R = TODO() + +fun foo(arg: Number) { +} + +fun main(args: Array) { + val x: Int = 0 + foo(x.convert()) +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/argumentMappedWithError.txt b/compiler/testData/ir/irText/expressions/argumentMappedWithError.txt new file mode 100644 index 00000000000..e85f4b1cbab --- /dev/null +++ b/compiler/testData/ir/irText/expressions/argumentMappedWithError.txt @@ -0,0 +1,19 @@ +FILE /argumentMappedWithError.kt + FUN public fun kotlin.Number.convert(): R + TYPE_PARAMETER + $receiver: VALUE_PARAMETER this@convert: Number + BLOCK_BODY + RETURN type=kotlin.Nothing from='convert() on Number: R' + CALL 'TODO(): Nothing' type=kotlin.Nothing origin=null + FUN public fun foo(arg: kotlin.Number): kotlin.Unit + VALUE_PARAMETER value-parameter arg: kotlin.Number + BLOCK_BODY + FUN public fun main(args: kotlin.Array): kotlin.Unit + VALUE_PARAMETER value-parameter args: kotlin.Array + BLOCK_BODY + VAR val x: kotlin.Int = 0 + CONST Int type=kotlin.Int value='0' + CALL 'foo(Number): Unit' type=kotlin.Unit origin=null + arg: CALL 'convert() on Number: Number' type=kotlin.Number origin=null + : Number + $receiver: GET_VAR 'x: Int' type=kotlin.Int origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index d9e715fc282..6895372e9b5 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -467,6 +467,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/expressions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("argumentMappedWithError.kt") + public void testArgumentMappedWithError() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/expressions/argumentMappedWithError.kt"); + doTest(fileName); + } + @TestMetadata("arrayAccess.kt") public void testArrayAccess() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/expressions/arrayAccess.kt");