diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index e7a6253abf8..e6b68023199 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -33381,6 +33381,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealias.kt"); } + @Test + @TestMetadata("expectActualTypealiasCoercion.kt") + public void testExpectActualTypealiasCoercion() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt"); + } + @Test @TestMetadata("expectInterfaceInSupertypes.kt") public void testExpectInterfaceInSupertypes() throws Exception { @@ -51873,6 +51879,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloadResolutionAmbiguity.kt") + public void testImplicitIntegerCoercionOverloadResolutionAmbiguity() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt"); + } + @Test @TestMetadata("inUnsignedDownTo.kt") public void testInUnsignedDownTo() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 5508055755c..af78e50789a 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -33381,6 +33381,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealias.kt"); } + @Test + @TestMetadata("expectActualTypealiasCoercion.kt") + public void testExpectActualTypealiasCoercion() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt"); + } + @Test @TestMetadata("expectInterfaceInSupertypes.kt") public void testExpectInterfaceInSupertypes() throws Exception { @@ -51873,6 +51879,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloadResolutionAmbiguity.kt") + public void testImplicitIntegerCoercionOverloadResolutionAmbiguity() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt"); + } + @Test @TestMetadata("inUnsignedDownTo.kt") public void testInUnsignedDownTo() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index b4459d001bb..4ab67fc985a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -517,8 +517,11 @@ private fun getExpectedTypeWithImplicintIntegerCoercion( if (!parameter.isMarkedWithImplicitIntegerCoercion) return null val argumentType = - if (argument.isIntegerLiteralOrOperatorCall()) argument.resultType.coneType - else { + if (argument.isIntegerLiteralOrOperatorCall()) { + if (candidateExpectedType.fullyExpandedType(session).isUnsignedTypeOrNullableUnsignedType) + argument.resultType.coneType + else null + } else { argument.calleeReference?.toResolvedCallableSymbol()?.takeIf { it.rawStatus.isConst && it.isMarkedWithImplicitIntegerCoercion }?.resolvedReturnType diff --git a/compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt b/compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt new file mode 100644 index 00000000000..a37adf1cc7c --- /dev/null +++ b/compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt @@ -0,0 +1,38 @@ +// TARGET_BACKEND: JVM_IR +// TARGET_BACKEND: NATIVE + +// IGNORE_BACKEND_K1: NATIVE +// !LANGUAGE: +MultiPlatformProjects +ImplicitSignedToUnsignedIntegerConversion +// WITH_STDLIB + +// MODULE: common +// TARGET_PLATFORM: Common +// FILE: annotation.kt + +package kotlin.internal +annotation class ImplicitIntegerCoercion + +// FILE: common.kt +import kotlin.internal.ImplicitIntegerCoercion + +expect class Signed +expect value class Unsigned internal constructor(internal val data: Signed) + +class FooUnsigned { + constructor(@ImplicitIntegerCoercion x: Unsigned) {} + constructor(@ImplicitIntegerCoercion y: String) {} +} + +// MODULE: platform()()(common) +// FILE: platform.kt + +actual typealias Signed = Int +actual typealias Unsigned = UInt + +fun box(): String { + FooUnsigned(42) // coercion + FooUnsigned(42u) // match + FooUnsigned("42") // match + + return "OK" +} diff --git a/compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt b/compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt new file mode 100644 index 00000000000..c964b629964 --- /dev/null +++ b/compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt @@ -0,0 +1,55 @@ +// TARGET_BACKEND: JVM_IR +// TARGET_BACKEND: NATIVE + +// IGNORE_BACKEND_K1: ANDROID +// STATUS: +// This line has been added because of the `AndroidRunner` test. +// This test runner appends a path-like prefix to all fully-qualified names, +// but the compiler logic for `ImplicitSignedToUnsignedIntegerConversion` +// relies on the ability to check exactly `kotlin.internal.ImplicitIntegerCoercion`. + +// ISSUE: KT-57484 +// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion +// WITH_STDLIB + +// FILE: annotation.kt + +package kotlin.internal + +annotation class ImplicitIntegerCoercion + +// FILE: test.kt + +import kotlin.internal.ImplicitIntegerCoercion + +class FooInt { + constructor(@ImplicitIntegerCoercion x: Int) {} + constructor(@ImplicitIntegerCoercion y: String) {} +} + +class FooUInt { + constructor(@ImplicitIntegerCoercion x: UInt) {} + constructor(@ImplicitIntegerCoercion y: String) {} +} + +typealias myUInt = UInt +class FooMyUInt { + constructor(@ImplicitIntegerCoercion x: myUInt) {} + constructor(@ImplicitIntegerCoercion y: String) {} +} + +fun box(): String { + FooInt(19) // overload match + // `FooInt(19u)` is invalid in K1/N and K2/N + FooInt("19") // overload match + + FooUInt(42) // coercion + FooUInt(42u) // overload match + FooUInt("42") // overload match + + FooMyUInt(153) // coercion + FooMyUInt(153u) // overload match + FooMyUInt("153") // overload match + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 9b4071ded14..f72c38f4198 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -33381,6 +33381,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealias.kt"); } + @Test + @TestMetadata("expectActualTypealiasCoercion.kt") + public void testExpectActualTypealiasCoercion() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt"); + } + @Test @TestMetadata("expectInterfaceInSupertypes.kt") public void testExpectInterfaceInSupertypes() throws Exception { @@ -51873,6 +51879,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloadResolutionAmbiguity.kt") + public void testImplicitIntegerCoercionOverloadResolutionAmbiguity() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt"); + } + @Test @TestMetadata("inUnsignedDownTo.kt") public void testInUnsignedDownTo() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 5667ba705f3..f318fd2103b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -33381,6 +33381,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealias.kt"); } + @Test + @TestMetadata("expectActualTypealiasCoercion.kt") + public void testExpectActualTypealiasCoercion() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt"); + } + @Test @TestMetadata("expectInterfaceInSupertypes.kt") public void testExpectInterfaceInSupertypes() throws Exception { @@ -51873,6 +51879,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloadResolutionAmbiguity.kt") + public void testImplicitIntegerCoercionOverloadResolutionAmbiguity() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt"); + } + @Test @TestMetadata("inUnsignedDownTo.kt") public void testInUnsignedDownTo() throws Exception { diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 246b4cb332b..cbb977a671b 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -4855,8 +4855,7 @@ interopTest("interop_cppSkia") { } interopTest("interop_cppSkiaSignature") { - disabled = (project.testTarget == 'wasm32' || // No interop for wasm yet. - isK2(project)) || // KT-57484 + disabled = (project.testTarget == 'wasm32') || // No interop for wasm yet. isAppleTarget(project) // KT-58422 source = "interop/cpp/skiaSignature.kt" interop = "cppSkiaSignature" @@ -4959,7 +4958,6 @@ if (PlatformInfo.isAppleTarget(project)) { } interopTestMultifile("interop_objc_tests") { - disabled = isK2(project) // KT-57504 source = "interop/objc/tests/" interop = 'objcTests' flags = ['-tr', '-e', 'main'] diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java index c0a1aac35d6..ad6200afb6d 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java @@ -26527,6 +26527,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealias.kt"); } + @Test + @TestMetadata("expectActualTypealiasCoercion.kt") + public void testExpectActualTypealiasCoercion() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt"); + } + @Test @TestMetadata("expectInterfaceInSupertypes.kt") public void testExpectInterfaceInSupertypes() throws Exception { @@ -40807,6 +40813,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloadResolutionAmbiguity.kt") + public void testImplicitIntegerCoercionOverloadResolutionAmbiguity() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt"); + } + @Test @TestMetadata("inUnsignedDownTo.kt") public void testInUnsignedDownTo() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java index 11cdb4873cf..1446abc3c59 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java @@ -27133,6 +27133,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealias.kt"); } + @Test + @TestMetadata("expectActualTypealiasCoercion.kt") + public void testExpectActualTypealiasCoercion() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt"); + } + @Test @TestMetadata("expectInterfaceInSupertypes.kt") public void testExpectInterfaceInSupertypes() throws Exception { @@ -41829,6 +41835,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloadResolutionAmbiguity.kt") + public void testImplicitIntegerCoercionOverloadResolutionAmbiguity() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt"); + } + @Test @TestMetadata("inUnsignedDownTo.kt") public void testInUnsignedDownTo() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 617e44b2687..b09cbf82cc1 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -26225,6 +26225,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealias.kt"); } + @Test + @TestMetadata("expectActualTypealiasCoercion.kt") + public void testExpectActualTypealiasCoercion() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt"); + } + @Test @TestMetadata("expectInterfaceInSupertypes.kt") public void testExpectInterfaceInSupertypes() throws Exception { @@ -40297,6 +40303,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloadResolutionAmbiguity.kt") + public void testImplicitIntegerCoercionOverloadResolutionAmbiguity() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt"); + } + @Test @TestMetadata("inUnsignedDownTo.kt") public void testInUnsignedDownTo() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java index cb3cb3c96a3..58a04499d39 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java @@ -26528,6 +26528,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealias.kt"); } + @Test + @TestMetadata("expectActualTypealiasCoercion.kt") + public void testExpectActualTypealiasCoercion() throws Exception { + runTest("compiler/testData/codegen/box/multiplatform/k2/basic/expectActualTypealiasCoercion.kt"); + } + @Test @TestMetadata("expectInterfaceInSupertypes.kt") public void testExpectInterfaceInSupertypes() throws Exception { @@ -40808,6 +40814,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloadResolutionAmbiguity.kt") + public void testImplicitIntegerCoercionOverloadResolutionAmbiguity() throws Exception { + runTest("compiler/testData/codegen/box/unsignedTypes/implicitIntegerCoercionOverloadResolutionAmbiguity.kt"); + } + @Test @TestMetadata("inUnsignedDownTo.kt") public void testInUnsignedDownTo() throws Exception {