JVM: add tests for optimized getDelegate
This commit is contained in:
+12
@@ -13198,12 +13198,24 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherCustom.kt")
|
||||
public void testDelegateToAnotherCustom() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherCustom.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherMutable.kt")
|
||||
public void testDelegateToAnotherMutable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherMutable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherReflection.kt")
|
||||
public void testDelegateToAnotherReflection() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherReflection.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToGenericJavaProperty.kt")
|
||||
public void testDelegateToGenericJavaProperty() throws Exception {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
var x: String
|
||||
get() = throw Exception("x's getter shouldn't be called")
|
||||
set(_) { throw Exception("x's setter shouldn't be called") }
|
||||
var y: String by ::x
|
||||
|
||||
var storage = "Fail"
|
||||
operator fun Any.getValue(thiz: Any?, property: Any?): String = storage
|
||||
operator fun Any.setValue(thiz: Any?, property: Any?, value: String) { storage = value }
|
||||
|
||||
fun box(): String {
|
||||
y = "OK"
|
||||
return y
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
// WITH_REFLECT
|
||||
// TARGET_BACKEND: JVM
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
import kotlin.reflect.full.getExtensionDelegate
|
||||
|
||||
class C(var x: Int) {
|
||||
var y by C::x
|
||||
var z by ::x
|
||||
}
|
||||
|
||||
class D(val c: C) {
|
||||
var y by c::x
|
||||
}
|
||||
|
||||
var x = 1
|
||||
var y by ::x
|
||||
var z by C(1)::x
|
||||
|
||||
var _x = -99
|
||||
var Int.x
|
||||
get() = this + _x
|
||||
set(v: Int) { _x = v - this }
|
||||
var Int.y by Int::x
|
||||
|
||||
inline fun <P : KProperty<*>, R> P.test(delegate: P.() -> R, get: R.() -> Int, set: R.(Int) -> Unit) {
|
||||
val ref = apply { isAccessible = true }.delegate()
|
||||
require(ref.get() == 1) { "$ref initial value is ${ref.get()}, not 1" }
|
||||
ref.set(2)
|
||||
require(ref.get() == 2) { "$ref after set(2) is ${ref.get()}, not 2" }
|
||||
ref.set(1)
|
||||
}
|
||||
|
||||
fun KMutableProperty0<Int>.test() =
|
||||
test({ getDelegate() as KMutableProperty0<Int> }, { get() }, { set(it) })
|
||||
|
||||
fun <T> KMutableProperty1<T, Int>.test(receiver: T) =
|
||||
test({ getDelegate(receiver) as KMutableProperty0<Int> }, { get() }, { set(it) })
|
||||
|
||||
fun <T> KMutableProperty1<T, Int>.test(receiver: T, receiver2: T) =
|
||||
test({ getDelegate(receiver) as KMutableProperty1<T, Int> }, { get(receiver2) }, { set(receiver2, it) })
|
||||
|
||||
fun box(): String {
|
||||
C::y.test(C(100), C(1))
|
||||
C::z.test(C(1))
|
||||
D::y.test(D(C(1)))
|
||||
::y.test()
|
||||
::z.test()
|
||||
Int::y.test({ getExtensionDelegate() as KMutableProperty1<Int, Int> }, { get(100) }, { set(100, it) })
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -13198,12 +13198,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherCustom.kt")
|
||||
public void testDelegateToAnotherCustom() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherCustom.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherMutable.kt")
|
||||
public void testDelegateToAnotherMutable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherMutable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherReflection.kt")
|
||||
public void testDelegateToAnotherReflection() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherReflection.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToGenericJavaProperty.kt")
|
||||
public void testDelegateToGenericJavaProperty() throws Exception {
|
||||
|
||||
+12
@@ -13198,12 +13198,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherCustom.kt")
|
||||
public void testDelegateToAnotherCustom() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherCustom.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherMutable.kt")
|
||||
public void testDelegateToAnotherMutable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherMutable.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToAnotherReflection.kt")
|
||||
public void testDelegateToAnotherReflection() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherReflection.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("delegateToGenericJavaProperty.kt")
|
||||
public void testDelegateToGenericJavaProperty() throws Exception {
|
||||
|
||||
+10
@@ -10722,11 +10722,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherCustom.kt")
|
||||
public void testDelegateToAnotherCustom() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherCustom.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherMutable.kt")
|
||||
public void testDelegateToAnotherMutable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherMutable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherReflection.kt")
|
||||
public void testDelegateToAnotherReflection() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherReflection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToGenericJavaProperty.kt")
|
||||
public void testDelegateToGenericJavaProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToGenericJavaProperty.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -9541,6 +9541,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherCustom.kt")
|
||||
public void testDelegateToAnotherCustom() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherCustom.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherMutable.kt")
|
||||
public void testDelegateToAnotherMutable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherMutable.kt");
|
||||
|
||||
Generated
+5
@@ -8947,6 +8947,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherCustom.kt")
|
||||
public void testDelegateToAnotherCustom() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherCustom.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherMutable.kt")
|
||||
public void testDelegateToAnotherMutable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherMutable.kt");
|
||||
|
||||
Generated
+5
@@ -8947,6 +8947,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnother.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherCustom.kt")
|
||||
public void testDelegateToAnotherCustom() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherCustom.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegateToAnotherMutable.kt")
|
||||
public void testDelegateToAnotherMutable() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/delegatedProperty/delegateToAnotherMutable.kt");
|
||||
|
||||
Reference in New Issue
Block a user