A new kind of synthetic accessors for backing fields, if accessed inside lambda / object literal / local class #KT-9657 Fixed

A set of tests provided
Also #KT-4867 Fixed
Also #KT-8750 Fixed
Slight codegen refactoring
This commit is contained in:
Mikhail Glukhikh
2015-10-21 12:06:21 +03:00
parent ccad435850
commit 4b6cb3ebce
18 changed files with 298 additions and 73 deletions
@@ -9,6 +9,12 @@ class A {
fun `access$getFoo$cp`(): Int = 1
fun `access$setFoo$cp`(d: Int) {}
val bar = 0
get() = { field }()
//synthetic field convention accessor
fun `access$getBar$lp`(a: A): Int = 7
companion object {
private var foo = 1;
@@ -26,7 +32,7 @@ class A {
fun test() {
{
foo = 2;
foo
foo + bar
}()
}
}
@@ -18,6 +18,11 @@ compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:1:7: e
fun `access$setFoo$cp`(d: kotlin.Int): kotlin.Unit
class A {
^
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getBar$lp(LA;)I):
fun <get-bar>(): kotlin.Int
fun `access$getBar$lp`(a: A): kotlin.Int
class A {
^
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:5:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I):
fun <get-foo>(): kotlin.Int
fun `access$getFoo$p`(a: A): kotlin.Int
@@ -38,22 +43,27 @@ compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:10:5:
fun `access$setFoo$cp`(d: kotlin.Int): kotlin.Unit
fun `access$setFoo$cp`(d: Int) {}
^
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:12:15: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA$Companion;)I):
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:16:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getBar$lp(LA;)I):
fun <get-bar>(): kotlin.Int
fun `access$getBar$lp`(a: A): kotlin.Int
fun `access$getBar$lp`(a: A): Int = 7
^
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:18:15: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA$Companion;)I):
fun <get-foo>(): kotlin.Int
fun `access$getFoo$p`(p: A.Companion): kotlin.Int
companion object {
^
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:12:15: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA$Companion;I)V):
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:18:15: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA$Companion;I)V):
fun <set-foo>(<set-?>: kotlin.Int): kotlin.Unit
fun `access$setFoo$p`(p: A.Companion, d: kotlin.Int): kotlin.Unit
companion object {
^
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:22:9: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA$Companion;)I):
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:28:9: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA$Companion;)I):
fun <get-foo>(): kotlin.Int
fun `access$getFoo$p`(p: A.Companion): kotlin.Int
fun `access$getFoo$p`(p: A.Companion): Int = 1
^
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:23:9: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA$Companion;I)V):
compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:29:9: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA$Companion;I)V):
fun <set-foo>(<set-?>: kotlin.Int): kotlin.Unit
fun `access$setFoo$p`(p: A.Companion, d: kotlin.Int): kotlin.Unit
fun `access$setFoo$p`(p: A.Companion, d: Int) {}
@@ -0,0 +1,15 @@
abstract class Your {
abstract val your: String
fun foo() = your
}
class My {
val back = "O"
val my: String
get() = object : Your() {
override val your = back
}.foo() + "K"
}
fun box() = My().my
@@ -0,0 +1,6 @@
class My {
val my: String = "O"
get() = { field }() + "K"
}
fun box() = My().my
@@ -0,0 +1,18 @@
class My {
var my: String = "U"
get() = { field }()
set(arg) {
class Local {
fun foo() {
field = arg + "K"
}
}
Local().foo()
}
}
fun box(): String {
val m = My()
m.my = "O"
return m.my
}
@@ -0,0 +1,14 @@
abstract class Your {
abstract val your: String
fun foo() = your
}
class My {
val my: String = "O"
get() = object : Your() {
override val your = field
}.foo() + "K"
}
fun box() = My().my
@@ -0,0 +1,15 @@
abstract class Your {
abstract val your: String
fun foo() = your
}
class My {
private val back = "O"
val my: String
get() = object : Your() {
override val your = back
}.foo() + "K"
}
fun box() = My().my
@@ -0,0 +1,8 @@
class My {
companion object {
val my: String = "O"
get() = { field }() + "K"
}
}
fun box() = My.my
@@ -0,0 +1,4 @@
val my: String = "O"
get() = { field }() + "K"
fun box() = my