Generate function from Any for inline classes same as for data classes
#KT-24873 Fixed #KT-25293 Fixed #KT-25299 Fixed
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(val u: Int)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(a1: Any, a2: UInt?, a3: Any?, a4: Any?) {
|
||||
val b1 = a1 as UInt // checkcast, unbox
|
||||
val b2 = a2 as UInt // unbox
|
||||
@@ -9,6 +13,7 @@ fun test(a1: Any, a2: UInt?, a3: Any?, a4: Any?) {
|
||||
val b4 = a4 as? UInt // instanceof, checkcast
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 3 CHECKCAST UInt
|
||||
// 2 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
|
||||
Vendored
+5
-1
@@ -1,13 +1,17 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(private val data: Int)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun f() {
|
||||
val unull = UInt(1) ?: null
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKESTATIC UInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
+5
-1
@@ -1,17 +1,21 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(val u: Int)
|
||||
|
||||
fun <T> takeVarargs(vararg e: T) {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(u1: UInt, u2: UInt, u3: UInt?) {
|
||||
takeVarargs(u1, u2) // 2 box
|
||||
takeVarargs(u3)
|
||||
takeVarargs(u1, u3) // box
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 3 INVOKESTATIC UInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
+5
@@ -1,8 +1,12 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class AsInt(val value: Int)
|
||||
inline class AsAny(val value: Any)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun takeAny(a: Any) {}
|
||||
|
||||
fun test() {
|
||||
@@ -10,6 +14,7 @@ fun test() {
|
||||
takeAny(AsAny(123)) // box int, box inline class
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 1 INVOKESTATIC AsInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL AsInt.unbox
|
||||
|
||||
|
||||
Vendored
+5
@@ -1,7 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class Result<T>(val a: Any?)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
val a = Result<Int>(1) // valueOf
|
||||
val b = Result<String>("sample")
|
||||
@@ -10,6 +14,7 @@ fun test() {
|
||||
val d = Result<Result<Int>>(Result<Int>(1)) // valueOf
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKESTATIC Result\$Erased.box
|
||||
// 0 INVOKEVIRTUAL Result.unbox
|
||||
|
||||
|
||||
Vendored
+4
-1
@@ -1,5 +1,7 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class Foo(val a: Int) {
|
||||
fun member(): String = ""
|
||||
}
|
||||
@@ -9,6 +11,7 @@ fun <T> T.idExtension(): T = this
|
||||
|
||||
fun Foo.extension() {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(f: Foo) {
|
||||
id(f) // box
|
||||
@@ -21,8 +24,8 @@ fun test(f: Foo) {
|
||||
val b = id(f).idExtension() // box unbox
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 6 INVOKESTATIC Foo\$Erased.box
|
||||
// 4 INVOKEVIRTUAL Foo.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
Vendored
+5
@@ -1,7 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(private val u: Int)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(x: UInt?, y: UInt) {
|
||||
val a = run {
|
||||
x!!
|
||||
@@ -12,6 +16,7 @@ fun test(x: UInt?, y: UInt) {
|
||||
}
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKESTATIC UInt\$Erased.box
|
||||
// 1 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
|
||||
Vendored
+3
-2
@@ -16,11 +16,12 @@ fun test() {
|
||||
} // unbox ULong
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 1 INVOKESTATIC UInt\$Erased.box
|
||||
// 1 INVOKEVIRTUAL UInt.unbox
|
||||
// 2 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
// 1 INVOKESTATIC ULong\$Erased.box
|
||||
// 1 INVOKEVIRTUAL ULong.unbox
|
||||
// 2 INVOKEVIRTUAL ULong.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class Foo(val a: Int)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun <T> id(x: T): T = x
|
||||
inline fun <T> inlinedId(x: T): T = x
|
||||
|
||||
@@ -18,8 +22,8 @@ fun test(f: Foo) {
|
||||
val b = inlinedId(f).inlinedIdExtension()
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 2 INVOKESTATIC Foo\$Erased.box
|
||||
// 1 INVOKEVIRTUAL Foo.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
+5
@@ -1,7 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class ULong(val l: Long)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun nonLocal(): ULong? {
|
||||
val u = ULong(0)
|
||||
|
||||
@@ -22,6 +26,7 @@ fun labeled(): ULong? {
|
||||
}
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 2 INVOKESTATIC ULong\$Erased.box
|
||||
// 0 INVOKEVIRTUAL ULong.unbox
|
||||
|
||||
|
||||
+1
-1
@@ -15,4 +15,4 @@ inline class Foo(val x: Int) {
|
||||
// 2 INVOKESTATIC Foo\$Erased.empty \(I\)V
|
||||
// 2 INVOKESTATIC Foo\$Erased.withParam \(ILjava/lang/String;\)V
|
||||
// 2 INVOKESTATIC Foo\$Erased.withInlineClassParam \(II\)V
|
||||
// 0 INVOKEVIRTUAL
|
||||
// 5 INVOKEVIRTUAL
|
||||
compiler/testData/codegen/bytecodeText/inlineClasses/inlineClassBoxingUnboxingInsideInlinedLambda.kt
Vendored
+5
@@ -1,7 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(val value: Int)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(x: UInt?) {
|
||||
x?.myLet { // unbox
|
||||
takeUInt(it)
|
||||
@@ -24,6 +28,7 @@ fun takeNullableUInt(y: UInt?) {}
|
||||
|
||||
inline fun <T> T.myLet(f: (T) -> Unit) = f(this)
|
||||
|
||||
// @TestKt.class:
|
||||
// 1 INVOKESTATIC UInt\$Erased.box
|
||||
// 5 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
|
||||
Vendored
+5
@@ -1,5 +1,7 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class WithPrimitive(val a: Int)
|
||||
fun takeWithPrimitive(a: WithPrimitive) {}
|
||||
|
||||
@@ -9,6 +11,8 @@ fun takeWithReference(a: WithReference) {}
|
||||
inline class WithNullableReference(val a: Any?)
|
||||
fun takeWithNullableReference(a: WithNullableReference) {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun foo(a: WithPrimitive?, b: WithPrimitive) {
|
||||
takeWithPrimitive(a!!) // unbox
|
||||
takeWithPrimitive(a) // unbox
|
||||
@@ -28,6 +32,7 @@ fun baz(a: WithNullableReference?, b: WithNullableReference) {
|
||||
takeWithNullableReference(b!!)
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 2 INVOKEVIRTUAL WithPrimitive\.unbox
|
||||
// 0 INVOKEVIRTUAL WithReference\.unbox
|
||||
// 3 INVOKEVIRTUAL WithNullableReference\.unbox
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(val u: Int) {
|
||||
fun member() {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun UInt?.extension() {}
|
||||
|
||||
fun test(a: Any, b: Any?) {
|
||||
@@ -16,6 +20,7 @@ fun test(a: Any, b: Any?) {
|
||||
}
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 2 INSTANCEOF UInt
|
||||
// 2 CHECKCAST UInt
|
||||
|
||||
|
||||
compiler/testData/codegen/bytecodeText/inlineClasses/passInlineClassesWithSpreadOperatorToVarargs.kt
Vendored
+5
@@ -1,7 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(val u: Int)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun <T> takeVarargs(vararg e: T) {}
|
||||
|
||||
fun test(u1: UInt, u2: UInt, us: Array<UInt>) {
|
||||
@@ -9,6 +13,7 @@ fun test(u1: UInt, u2: UInt, us: Array<UInt>) {
|
||||
takeVarargs(u1, u2, *us) // 2 box + ...
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 2 INVOKESTATIC UInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
|
||||
Vendored
+5
@@ -1,7 +1,11 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(val value: Int)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(u1: UInt, u2: UInt) {
|
||||
val a = u1.value
|
||||
|
||||
@@ -9,6 +13,7 @@ fun test(u1: UInt, u2: UInt) {
|
||||
val c = u1.value + u2.value
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKESTATIC UInt\$Erased.getValue
|
||||
// 0 INVOKESTATIC UInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ fun test() {
|
||||
fun takeUInt(u: UInt) {}
|
||||
|
||||
// 1 INVOKESTATIC UInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL UInt.unbox
|
||||
// 1 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
// 0 INVOKEVIRTUAL UIntIterator.iterator
|
||||
// 1 INVOKESTATIC kotlin/jvm/internal/ArrayIteratorsKt.iterator
|
||||
|
||||
+5
-1
@@ -1,5 +1,7 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(private val value: Int) {
|
||||
fun asInt() = value
|
||||
}
|
||||
@@ -12,12 +14,14 @@ inline class UIntArray(private val intArray: IntArray) {
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun UIntArray.swap(i: Int, j: Int) {
|
||||
this[j] = this[i].also { this[i] = this[j] }
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKEVIRTUAL UInt.unbox
|
||||
// 0 INVOKESTATIC UInt\$Erased.box
|
||||
|
||||
// 0 intValue
|
||||
// 0 valueOf
|
||||
+5
@@ -1,12 +1,17 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class UInt(private val u: Int)
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(x: UInt?, y: UInt) {
|
||||
val a = x ?: y // unbox
|
||||
val b = x ?: x!! // unbox unbox
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKESTATIC UInt\$Erased.box
|
||||
// 3 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
|
||||
+5
@@ -1,9 +1,13 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class Foo(val x: Int) {
|
||||
fun member() {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun Foo.extension() {}
|
||||
fun <T> T.genericExtension() {}
|
||||
|
||||
@@ -13,6 +17,7 @@ fun test(f: Foo?) {
|
||||
f?.genericExtension()
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKESTATIC Foo\$Erased.box
|
||||
// 2 INVOKEVIRTUAL Foo.unbox
|
||||
|
||||
|
||||
Vendored
+5
@@ -1,9 +1,13 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class Result<T>(val a: Any?) {
|
||||
fun typed(): T = a as T
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun <K> materialize(): K = TODO()
|
||||
|
||||
fun test(asInt: Result<Int>, asString: Result<String>, asResult: Result<Result<Int>>) {
|
||||
@@ -21,6 +25,7 @@ fun test(asInt: Result<Int>, asString: Result<String>, asResult: Result<Result<I
|
||||
asResult.typed()
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKESTATIC Result\$Erased.box
|
||||
// 3 INVOKEVIRTUAL Result.unbox
|
||||
|
||||
|
||||
+5
-1
@@ -1,9 +1,13 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
inline class Foo(val x: Int) {
|
||||
fun member() {}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun Foo?.extensionOnNullable() {}
|
||||
|
||||
fun test(f: Foo?) {
|
||||
@@ -21,8 +25,8 @@ fun test(f: Foo?) {
|
||||
}
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 INVOKESTATIC Foo\$Erased.box
|
||||
// 2 INVOKEVIRTUAL Foo.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
Reference in New Issue
Block a user