diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 81d806407ee..9e4718c1854 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -593,6 +593,26 @@ task classDelegation_withBridge(type: RunKonanTest) { source = "codegen/classDelegation/withBridge.kt" } +task delegatedProperty_simpleVal(type: RunKonanTest) { + goldValue = "x\n42\n" + source = "codegen/delegatedProperty/simpleVal.kt" +} + +task delegatedProperty_simpleVar(type: RunKonanTest) { + goldValue = "get x\n42\nset x\nget x\n117\n" + source = "codegen/delegatedProperty/simpleVar.kt" +} + +task delegatedProperty_packageLevel(type: RunKonanTest) { + goldValue = "x\n42\n" + source = "codegen/delegatedProperty/packageLevel.kt" +} + +task delegatedProperty_local(type: RunKonanTest) { + goldValue = "x\n42\n" + source = "codegen/delegatedProperty/local.kt" +} + task array0(type: RunKonanTest) { goldValue = "5\n6\n7\n8\n9\n10\n11\n12\n13\n" source = "runtime/collections/array0.kt" diff --git a/backend.native/tests/codegen/delegatedProperty/local.kt b/backend.native/tests/codegen/delegatedProperty/local.kt new file mode 100644 index 00000000000..f80c389e7ce --- /dev/null +++ b/backend.native/tests/codegen/delegatedProperty/local.kt @@ -0,0 +1,18 @@ +import kotlin.reflect.KProperty + +fun foo(): Int { + class Delegate { + operator fun getValue(receiver: Any?, p: KProperty<*>): Int { + println(p.name) + return 42 + } + } + + val x: Int by Delegate() + + return x +} + +fun main(args: Array) { + println(foo()) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/delegatedProperty/packageLevel.kt b/backend.native/tests/codegen/delegatedProperty/packageLevel.kt new file mode 100644 index 00000000000..78002766016 --- /dev/null +++ b/backend.native/tests/codegen/delegatedProperty/packageLevel.kt @@ -0,0 +1,14 @@ +import kotlin.reflect.KProperty + +class Delegate { + operator fun getValue(receiver: Any?, p: KProperty<*>): Int { + println(p.name) + return 42 + } +} + +val x: Int by Delegate() + +fun main(args: Array) { + println(x) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/delegatedProperty/simpleVal.kt b/backend.native/tests/codegen/delegatedProperty/simpleVal.kt new file mode 100644 index 00000000000..efa491997fe --- /dev/null +++ b/backend.native/tests/codegen/delegatedProperty/simpleVal.kt @@ -0,0 +1,16 @@ +import kotlin.reflect.KProperty + +class Delegate { + operator fun getValue(receiver: Any?, p: KProperty<*>): Int { + println(p.name) + return 42 + } +} + +class C { + val x: Int by Delegate() +} + +fun main(args: Array) { + println(C().x) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/delegatedProperty/simpleVar.kt b/backend.native/tests/codegen/delegatedProperty/simpleVar.kt new file mode 100644 index 00000000000..4e934e1b7a4 --- /dev/null +++ b/backend.native/tests/codegen/delegatedProperty/simpleVar.kt @@ -0,0 +1,26 @@ +import kotlin.reflect.KProperty + +class Delegate { + var f: Int = 42 + + operator fun getValue(receiver: Any?, p: KProperty<*>): Int { + println("get ${p.name}") + return f + } + + operator fun setValue(receiver: Any?, p: KProperty<*>, value: Int) { + println("set ${p.name}") + f = value + } +} + +class C { + var x: Int by Delegate() +} + +fun main(args: Array) { + val c = C() + println(c.x) + c.x = 117 + println(c.x) +} \ No newline at end of file