Support references to extension properties in JVM codegen
#KT-1183 In Progress
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
val String.id: String
|
||||
get() = this
|
||||
|
||||
fun box(): String {
|
||||
val pr = String::id
|
||||
|
||||
if (pr["123"] != "123") return "Fail value: ${pr["123"]}"
|
||||
|
||||
if (pr.name != "id") return "Fail name: ${pr.name}"
|
||||
|
||||
return pr.get("OK")
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
var storage = 0
|
||||
|
||||
var Int.foo: Int
|
||||
get() {
|
||||
return this + storage
|
||||
}
|
||||
set(value) {
|
||||
storage = this + value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val pr = Int::foo
|
||||
if (pr.get(42) != 42) return "Fail 1: ${pr[42]}"
|
||||
pr.set(200, 39)
|
||||
if (pr.get(-239) != 0) return "Fail 2: ${pr[-239]}"
|
||||
if (storage != 239) return "Fail 3: $storage"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package a
|
||||
|
||||
public var topLevel: Int = 42
|
||||
|
||||
public val String.extension: Long
|
||||
get() = length.toLong()
|
||||
@@ -0,0 +1,14 @@
|
||||
import a.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val f = ::topLevel
|
||||
val x1 = f.get()
|
||||
if (x1 != 42) throw AssertionError("Fail x1: $x1")
|
||||
f.set(239)
|
||||
val x2 = f.get()
|
||||
if (x2 != 239) throw AssertionError("Fail x2: $x2")
|
||||
|
||||
val g = String::extension
|
||||
val y1 = g.get("abcde")
|
||||
if (y1 != 5L) throw AssertionError("Fail y1: $y1")
|
||||
}
|
||||
Reference in New Issue
Block a user