[K2/N] IntegerLiteralType coercion only to unsigned integer types
^KT-57484 Fixed Merge-request: KT-MR-10270 Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
a534708900
commit
fde8909e6f
+12
@@ -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 {
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
+38
@@ -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"
|
||||
}
|
||||
Vendored
+55
@@ -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"
|
||||
}
|
||||
+12
@@ -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 {
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
@@ -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']
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
+12
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user