[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
+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"
|
||||
}
|
||||
Reference in New Issue
Block a user