diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt index 1b953aed148..77b058767c7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt @@ -1042,7 +1042,8 @@ class MethodInliner( val safeToUseArgumentKotlinType = directOrder.size == directOrderOfArguments.size && directOrderOfArguments.size == directOrderOfInvokeParameters.size - directOrder.asReversed().forEachIndexed { index, type -> + for (index in directOrder.lastIndex downTo 0) { + val type = directOrder[index] currentShift -= type.size val typeOnStack = actualParams[index] diff --git a/compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt b/compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt new file mode 100644 index 00000000000..7567f934e54 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +InlineClasses +// IGNORE_BACKEND: JVM_IR + +inline class Z(val int: Int) +inline class L(val long: Long) + +inline fun s0(x: T, fn: (Int, T) -> R) = fn(0, x) + +inline fun weirdMix(x: T, fn: (Int, T, Long, T) -> R) = fn(0, x, 0L, x) + +fun testS0Z(x: Z) = s0(x) { _, xx -> Z(xx.int + 1) } +fun testS0L(x: L) = s0(x) { _, xx -> L(xx.long + 1L) } + +fun testWeirdMixZ(x: Z) = weirdMix(x) { _, xx, _, _ -> Z(xx.int + 1) } +fun testWeirdMixL(x: L) = weirdMix(x) { _, xx, _, _ -> L(xx.long + 1L) } + +fun box(): String { + if (testS0Z(Z(42)).int != 43) throw AssertionError() + if (testS0L(L(42L)).long != 43L) throw AssertionError() + + if (testWeirdMixZ(Z(42)).int != 43) throw AssertionError() + if (testWeirdMixL(L(42L)).long != 43L) throw AssertionError() + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt b/compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt new file mode 100644 index 00000000000..fc71516c5a7 --- /dev/null +++ b/compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt @@ -0,0 +1,12 @@ +// IGNORE_BACKEND: JVM_IR, JS, JS_IR +// WITH_UNSIGNED + +fun box(): String { + val a = listOf(1u, 2u, 3u) + var sum = 0 + a.forEachIndexed { index, uInt -> + sum = sum * 10 + (index + 1) * uInt.toInt() + } + if (sum != 149) throw AssertionError() + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 559e9f39ac1..73883d6c5e2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11570,6 +11570,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt"); } + @TestMetadata("inlineClassesInInlineLambdaParameters.kt") + public void testInlineClassesInInlineLambdaParameters() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt"); + } + @TestMetadata("inlineFunctionInsideInlineClass.kt") public void testInlineFunctionInsideInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt"); @@ -22000,6 +22005,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt"); } + @TestMetadata("forEachIndexedInListOfUInts.kt") + public void testForEachIndexedInListOfUInts() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt"); + } + @TestMetadata("iterateOverArrayOfUnsignedValues.kt") public void testIterateOverArrayOfUnsignedValues() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1da9477fb38..6bff014f99e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11570,6 +11570,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt"); } + @TestMetadata("inlineClassesInInlineLambdaParameters.kt") + public void testInlineClassesInInlineLambdaParameters() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt"); + } + @TestMetadata("inlineFunctionInsideInlineClass.kt") public void testInlineFunctionInsideInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt"); @@ -22000,6 +22005,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt"); } + @TestMetadata("forEachIndexedInListOfUInts.kt") + public void testForEachIndexedInListOfUInts() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt"); + } + @TestMetadata("iterateOverArrayOfUnsignedValues.kt") public void testIterateOverArrayOfUnsignedValues() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index c2b9dc1b2f4..a7853e3be0c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11570,6 +11570,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt"); } + @TestMetadata("inlineClassesInInlineLambdaParameters.kt") + public void testInlineClassesInInlineLambdaParameters() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt"); + } + @TestMetadata("inlineFunctionInsideInlineClass.kt") public void testInlineFunctionInsideInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt"); @@ -22000,6 +22005,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/unsignedTypes/evaluateConstructorOfUnsignedType.kt"); } + @TestMetadata("forEachIndexedInListOfUInts.kt") + public void testForEachIndexedInListOfUInts() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt"); + } + @TestMetadata("iterateOverArrayOfUnsignedValues.kt") public void testIterateOverArrayOfUnsignedValues() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 05ae17c4d8d..023cedae434 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -10130,6 +10130,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt"); } + @TestMetadata("inlineClassesInInlineLambdaParameters.kt") + public void testInlineClassesInInlineLambdaParameters() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt"); + } + @TestMetadata("inlineFunctionInsideInlineClass.kt") public void testInlineFunctionInsideInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt"); @@ -19850,6 +19855,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt"); } + @TestMetadata("forEachIndexedInListOfUInts.kt") + public void testForEachIndexedInListOfUInts() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt"); + } + @TestMetadata("iterateOverArrayOfUnsignedValues.kt") public void testIterateOverArrayOfUnsignedValues() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 1307580fb34..def02109e7f 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -11190,6 +11190,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesCheckCast.kt"); } + @TestMetadata("inlineClassesInInlineLambdaParameters.kt") + public void testInlineClassesInInlineLambdaParameters() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/inlineClassesInInlineLambdaParameters.kt"); + } + @TestMetadata("inlineFunctionInsideInlineClass.kt") public void testInlineFunctionInsideInlineClass() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/inlineFunctionInsideInlineClass.kt"); @@ -20910,6 +20915,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/unsignedTypes/boxConstValOfUnsignedType.kt"); } + @TestMetadata("forEachIndexedInListOfUInts.kt") + public void testForEachIndexedInListOfUInts() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt"); + } + @TestMetadata("iterateOverArrayOfUnsignedValues.kt") public void testIterateOverArrayOfUnsignedValues() throws Exception { runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");