diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java index f6e918a3221..3f59db197bd 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java @@ -2863,6 +2863,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI public void testVarInInit() throws Exception { runTest("compiler/testData/ir/irText/firProblems/VarInInit.kt"); } + + @Test + @TestMetadata("VarargIntegerLiteral.kt") + public void testVarargIntegerLiteral() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt"); + } } @Nested diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java index 5144e35c1c5..e3fc56035bf 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java @@ -2863,6 +2863,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest { public void testVarInInit() throws Exception { runTest("compiler/testData/ir/irText/firProblems/VarInInit.kt"); } + + @Test + @TestMetadata("VarargIntegerLiteral.kt") + public void testVarargIntegerLiteral() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt"); + } } @Nested diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveUtils.kt index 297301d56e1..a26df12b455 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveUtils.kt @@ -16,10 +16,8 @@ import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirNamedArgumentExpression import org.jetbrains.kotlin.fir.expressions.builder.buildVarargArgumentsExpression import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider -import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef -import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.types.ConstantValueKind @@ -39,7 +37,7 @@ internal fun remapArgumentsWithVararg( // The order of arguments in the mapping must be preserved for FIR2IR, hence we have to find where the vararg arguments end. // FIR2IR uses the mapping order to determine if arguments need to be reordered. val varargParameterTypeRef = varargParameter.returnTypeRef - val varargElementType = varargArrayType.arrayElementType() + val varargElementType = varargArrayType.arrayElementType()?.approximateIntegerLiteralType() val argumentList = argumentMapping.keys.toList() var indexAfterVarargs = argumentList.size val newArgumentMapping = linkedMapOf() diff --git a/compiler/testData/codegen/box/regressions/kt57487.kt b/compiler/testData/codegen/box/regressions/kt57487.kt index 70f29e860bf..226bb6873dc 100644 --- a/compiler/testData/codegen/box/regressions/kt57487.kt +++ b/compiler/testData/codegen/box/regressions/kt57487.kt @@ -1,6 +1,3 @@ -// KT-57487: Stdlib ArraysTest fails with `Class found but error nodes are not allowed` -// IGNORE_BACKEND_K2: NATIVE, JS_IR - // Minimized from libraries.stdlib.test.collections.ArraysTest.sortedTests() // Exception is: Class found but error nodes are not allowed fun > arrayData(vararg values: T, toArray: Array.() -> Unit) {} diff --git a/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.ir.txt b/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.ir.txt new file mode 100644 index 00000000000..7cc8813578d --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.ir.txt @@ -0,0 +1,87 @@ +FILE fqName: fileName:/VarargIntegerLiteral.kt + FUN name:arrayData visibility:public modality:FINAL (values:kotlin.Array.arrayData>, toArray:@[ExtensionFunctionType] kotlin.Function1.arrayData>, kotlin.Unit>) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Comparable.arrayData>] reified:false + VALUE_PARAMETER name:values index:0 type:kotlin.Array.arrayData> varargElementType:T of .arrayData [vararg] + VALUE_PARAMETER name:toArray index:1 type:@[ExtensionFunctionType] kotlin.Function1.arrayData>, kotlin.Unit> + BLOCK_BODY + FUN name:arrayLongInheritedData visibility:public modality:FINAL (values:kotlin.Array.arrayLongInheritedData>, toArray:@[ExtensionFunctionType] kotlin.Function1.arrayLongInheritedData>, kotlin.Unit>) returnType:kotlin.Unit + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Long] reified:false + VALUE_PARAMETER name:values index:0 type:kotlin.Array.arrayLongInheritedData> varargElementType:T of .arrayLongInheritedData [vararg] + VALUE_PARAMETER name:toArray index:1 type:@[ExtensionFunctionType] kotlin.Function1.arrayLongInheritedData>, kotlin.Unit> + BLOCK_BODY + FUN name:longArrayData visibility:public modality:FINAL <> (values:kotlin.LongArray, toArray:@[ExtensionFunctionType] kotlin.Function1) returnType:kotlin.Unit + VALUE_PARAMETER name:values index:0 type:kotlin.LongArray varargElementType:kotlin.Long [vararg] + VALUE_PARAMETER name:toArray index:1 type:@[ExtensionFunctionType] kotlin.Function1 + BLOCK_BODY + FUN name:shortArrayData visibility:public modality:FINAL <> (values:kotlin.ShortArray, toArray:@[ExtensionFunctionType] kotlin.Function1) returnType:kotlin.Unit + VALUE_PARAMETER name:values index:0 type:kotlin.ShortArray varargElementType:kotlin.Short [vararg] + VALUE_PARAMETER name:toArray index:1 type:@[ExtensionFunctionType] kotlin.Function1 + BLOCK_BODY + FUN name:arrayOfLongData visibility:public modality:FINAL <> (values:kotlin.LongArray, toArray:@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit>) returnType:kotlin.Unit + VALUE_PARAMETER name:values index:0 type:kotlin.LongArray varargElementType:kotlin.Long [vararg] + VALUE_PARAMETER name:toArray index:1 type:@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit> + BLOCK_BODY + FUN name:arrayOfShortData visibility:public modality:FINAL <> (values:kotlin.ShortArray, toArray:@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit>) returnType:kotlin.Unit + VALUE_PARAMETER name:values index:0 type:kotlin.ShortArray varargElementType:kotlin.Short [vararg] + VALUE_PARAMETER name:toArray index:1 type:@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit> + BLOCK_BODY + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + CALL 'public final fun arrayData (vararg values: T of .arrayData, toArray: @[ExtensionFunctionType] kotlin.Function1.arrayData>, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + : kotlin.Int + values: VARARG type=kotlin.Array varargElementType=kotlin.Int + CONST Int type=kotlin.Int value=42 + toArray: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Array) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$arrayData type:kotlin.Array + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .box' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun arrayLongInheritedData (vararg values: T of .arrayLongInheritedData, toArray: @[ExtensionFunctionType] kotlin.Function1.arrayLongInheritedData>, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + : kotlin.Long + values: VARARG type=kotlin.Array varargElementType=kotlin.Long + CONST Long type=kotlin.Long value=42 + toArray: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Array) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$arrayLongInheritedData type:kotlin.Array + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .box' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun longArrayData (vararg values: kotlin.Long, toArray: @[ExtensionFunctionType] kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + values: VARARG type=kotlin.LongArray varargElementType=kotlin.Long + CONST Long type=kotlin.Long value=42 + toArray: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.LongArray) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$longArrayData type:kotlin.LongArray + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .box' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun shortArrayData (vararg values: kotlin.Short, toArray: @[ExtensionFunctionType] kotlin.Function1): kotlin.Unit declared in ' type=kotlin.Unit origin=null + values: VARARG type=kotlin.ShortArray varargElementType=kotlin.Short + CONST Short type=kotlin.Short value=42 + toArray: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.ShortArray) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$shortArrayData type:kotlin.ShortArray + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .box' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun arrayOfLongData (vararg values: kotlin.Long, toArray: @[ExtensionFunctionType] kotlin.Function1, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + values: VARARG type=kotlin.LongArray varargElementType=kotlin.Long + CONST Long type=kotlin.Long value=42 + toArray: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Array) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$arrayOfLongData type:kotlin.Array + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .box' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + CALL 'public final fun arrayOfShortData (vararg values: kotlin.Short, toArray: @[ExtensionFunctionType] kotlin.Function1, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + values: VARARG type=kotlin.ShortArray varargElementType=kotlin.Short + CONST Short type=kotlin.Short value=42 + toArray: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Array) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$arrayOfShortData type:kotlin.Array + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .box' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" diff --git a/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt b/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt new file mode 100644 index 00000000000..fcd4f2e5470 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt @@ -0,0 +1,22 @@ +// FIR_IDENTICAL +fun > arrayData(vararg values: T, toArray: Array.() -> Unit) {} + +fun arrayLongInheritedData(vararg values: T, toArray: Array.() -> Unit) {} + +fun longArrayData(vararg values: Long, toArray: LongArray.() -> Unit) {} + +fun shortArrayData(vararg values: Short, toArray: ShortArray.() -> Unit) {} + +fun arrayOfLongData(vararg values: Long, toArray: Array.() -> Unit) {} + +fun arrayOfShortData(vararg values: Short, toArray: Array.() -> Unit) {} + +fun box(): String { + arrayData(42) { } + arrayLongInheritedData(42) { } + longArrayData(42) { } + shortArrayData(42) { } + arrayOfLongData(42) { } + arrayOfShortData(42) { } + return "OK" +} diff --git a/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt.txt b/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt.txt new file mode 100644 index 00000000000..0f3897a0136 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt.txt @@ -0,0 +1,45 @@ +fun > arrayData(vararg values: T, toArray: @ExtensionFunctionType Function1, Unit>) { +} + +fun arrayLongInheritedData(vararg values: T, toArray: @ExtensionFunctionType Function1, Unit>) { +} + +fun longArrayData(vararg values: Long, toArray: @ExtensionFunctionType Function1) { +} + +fun shortArrayData(vararg values: Short, toArray: @ExtensionFunctionType Function1) { +} + +fun arrayOfLongData(vararg values: Long, toArray: @ExtensionFunctionType Function1, Unit>) { +} + +fun arrayOfShortData(vararg values: Short, toArray: @ExtensionFunctionType Function1, Unit>) { +} + +fun box(): String { + arrayData(values = [42], toArray = local fun Array.() { + return Unit + } +) + arrayLongInheritedData(values = [42L], toArray = local fun Array.() { + return Unit + } +) + longArrayData(values = [42L], toArray = local fun LongArray.() { + return Unit + } +) + shortArrayData(values = [42S], toArray = local fun ShortArray.() { + return Unit + } +) + arrayOfLongData(values = [42L], toArray = local fun Array.() { + return Unit + } +) + arrayOfShortData(values = [42S], toArray = local fun Array.() { + return Unit + } +) + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java index b0aa6fcd431..01697902523 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java @@ -2863,6 +2863,12 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest public void testVarInInit() throws Exception { runTest("compiler/testData/ir/irText/firProblems/VarInInit.kt"); } + + @Test + @TestMetadata("VarargIntegerLiteral.kt") + public void testVarargIntegerLiteral() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt"); + } } @Nested diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java index f21a16bf7a1..f90f509a2ab 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java @@ -2024,6 +2024,11 @@ public class KlibIrTextTestCaseGenerated extends AbstractKlibIrTextTestCase { public void testVarInInit() throws Exception { runTest("compiler/testData/ir/irText/firProblems/VarInInit.kt"); } + + @TestMetadata("VarargIntegerLiteral.kt") + public void testVarargIntegerLiteral() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt"); + } } @TestMetadata("compiler/testData/ir/irText/js") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java index 994da3e6e32..573b0b3fb58 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java @@ -2323,6 +2323,12 @@ public class FirLightTreeJsIrTextTestGenerated extends AbstractFirLightTreeJsIrT public void testVarInInit() throws Exception { runTest("compiler/testData/ir/irText/firProblems/VarInInit.kt"); } + + @Test + @TestMetadata("VarargIntegerLiteral.kt") + public void testVarargIntegerLiteral() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt"); + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java index 3998fa46928..9cda6aa2aba 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java @@ -2323,6 +2323,12 @@ public class FirPsiJsIrTextTestGenerated extends AbstractFirPsiJsIrTextTest { public void testVarInInit() throws Exception { runTest("compiler/testData/ir/irText/firProblems/VarInInit.kt"); } + + @Test + @TestMetadata("VarargIntegerLiteral.kt") + public void testVarargIntegerLiteral() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt"); + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java index ef6b6a82cb2..a5a81084ac0 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java @@ -2323,6 +2323,12 @@ public class ClassicJsIrTextTestGenerated extends AbstractClassicJsIrTextTest { public void testVarInInit() throws Exception { runTest("compiler/testData/ir/irText/firProblems/VarInInit.kt"); } + + @Test + @TestMetadata("VarargIntegerLiteral.kt") + public void testVarargIntegerLiteral() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/VarargIntegerLiteral.kt"); + } } @Nested