mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-07 15:53:18 +00:00
'when' should use intrinsics for '=='
#KT-19029 Fixed Target versions 1.1.5 #KT-18818 Fixed Target versions 1.1.5
This commit is contained in:
14
compiler/testData/codegen/bytecodeText/when/kt18818.kt
vendored
Normal file
14
compiler/testData/codegen/bytecodeText/when/kt18818.kt
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun findUserId(username: String): Long? = null
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val userId = findUserId("abcd")
|
||||
|
||||
when (userId) {
|
||||
null -> println("User not found")
|
||||
else -> println("User ID: $userId")
|
||||
}
|
||||
}
|
||||
|
||||
// 0 areEqual
|
||||
27
compiler/testData/codegen/bytecodeText/when/noBoxingInDefaultWhenWithSpecialCases.kt
vendored
Normal file
27
compiler/testData/codegen/bytecodeText/when/noBoxingInDefaultWhenWithSpecialCases.kt
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// FILE: C.kt
|
||||
class CInt(val value: Int)
|
||||
val nCInt3: CInt? = CInt(3)
|
||||
|
||||
class CLong(val value: Long)
|
||||
val nCLong3: CLong? = CLong(3)
|
||||
|
||||
// FILE: test.kt
|
||||
fun testInt(i: Int?) =
|
||||
when (i) {
|
||||
0 -> "zero"
|
||||
42 -> "magic"
|
||||
else -> "other"
|
||||
}
|
||||
|
||||
fun testLong(i: Long?) =
|
||||
when (i) {
|
||||
0L -> "zero"
|
||||
42L -> "magic"
|
||||
else -> "other"
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 valueOf
|
||||
// 0 Integer.valueOf
|
||||
// 0 Long.valueOf
|
||||
// 0 areEqual
|
||||
10
compiler/testData/codegen/bytecodeText/when/whenNull.kt
vendored
Normal file
10
compiler/testData/codegen/bytecodeText/when/whenNull.kt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
fun test(a: Any?, b: Any?, c: Any?) {
|
||||
when (null) {
|
||||
a -> throw IllegalArgumentException("a is null")
|
||||
b -> throw IllegalArgumentException("b is null")
|
||||
c -> throw IllegalArgumentException("c is null")
|
||||
}
|
||||
}
|
||||
|
||||
// 0 areEqual
|
||||
// 3 IFNONNULL
|
||||
10
compiler/testData/codegen/bytecodeText/when/whenZero.kt
vendored
Normal file
10
compiler/testData/codegen/bytecodeText/when/whenZero.kt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
fun test(a: Int, b: Int, c: Int) {
|
||||
when (0) {
|
||||
a -> throw IllegalArgumentException("a is 0")
|
||||
b -> throw IllegalArgumentException("b is 0")
|
||||
c -> throw IllegalArgumentException("c is 0")
|
||||
}
|
||||
}
|
||||
|
||||
// 0 IF_ICMPNE
|
||||
// 3 IFNE
|
||||
Reference in New Issue
Block a user