Change synthetic accessor method names to "access$..."
As per discussion in https://youtrack.jetbrains.com/issue/KT-6870
This commit is contained in:
@@ -23,7 +23,7 @@ class SubTr : Tr {
|
||||
// Clashing synthetic accessors are only reported in compiler, IDE doesn't see them
|
||||
class C {
|
||||
private fun f() {}
|
||||
fun `f$b$0`(c: C) {}
|
||||
fun `access$f$0`(c: C) {}
|
||||
|
||||
class Nested {
|
||||
|
||||
@@ -31,4 +31,4 @@ class C {
|
||||
C().f()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
WARNING: compiler/testData/cli/jvm/signatureClash.kt: (26, 17) Parameter 'c' is never used
|
||||
WARNING: compiler/testData/cli/jvm/signatureClash.kt: (26, 22) Parameter 'c' is never used
|
||||
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (6, 5) Accidental override: The following declarations have the same JVM signature (getX()I):
|
||||
fun getX(): kotlin.Int
|
||||
fun <get-x>(): kotlin.Int
|
||||
@@ -20,10 +20,10 @@ ERROR: compiler/testData/cli/jvm/signatureClash.kt: (19, 7) Platform declaration
|
||||
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (20, 5) Platform declaration clash: The following declarations have the same JVM signature (getTr()I):
|
||||
fun <get-tr>(): kotlin.Int
|
||||
fun getTr(): kotlin.Int
|
||||
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (24, 7) Platform declaration clash: The following declarations have the same JVM signature (f$b$0(LC;)V):
|
||||
fun `f$b$0`(c: C): kotlin.Unit
|
||||
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (24, 7) Platform declaration clash: The following declarations have the same JVM signature (access$f$0(LC;)V):
|
||||
fun `access$f$0`(c: C): kotlin.Unit
|
||||
fun f(): kotlin.Unit
|
||||
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (26, 5) Platform declaration clash: The following declarations have the same JVM signature (f$b$0(LC;)V):
|
||||
fun `f$b$0`(c: C): kotlin.Unit
|
||||
ERROR: compiler/testData/cli/jvm/signatureClash.kt: (26, 5) Platform declaration clash: The following declarations have the same JVM signature (access$f$0(LC;)V):
|
||||
fun `access$f$0`(c: C): kotlin.Unit
|
||||
fun f(): kotlin.Unit
|
||||
COMPILATION_ERROR
|
||||
@@ -1,14 +1,14 @@
|
||||
open class Base {
|
||||
open fun `foo$b$0`(d: Derived) {}
|
||||
open fun `access$foo$0`(d: Derived) {}
|
||||
|
||||
open fun `getBar$b$1`(d: Derived): Int = 1
|
||||
open fun `setBar$b$1`(d: Derived, i: Int) {}
|
||||
open fun `access$getBar$1`(d: Derived): Int = 1
|
||||
open fun `access$setBar$1`(d: Derived, i: Int) {}
|
||||
|
||||
open fun `getBaz$b$2`(d: Derived): Int = 1
|
||||
open fun `access$getBaz$2`(d: Derived): Int = 1
|
||||
|
||||
open fun `getBoo$b$3`(d: Derived): Int = 1
|
||||
open fun `access$getBoo$3`(d: Derived): Int = 1
|
||||
|
||||
open fun `setBar1$b$4`(d: Derived, i: Int) {}
|
||||
open fun `access$setBar1$4`(d: Derived, i: Int) {}
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
WARNING: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (34, 17) Variable 's' is never used
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (15, 5) Accidental override: The following declarations have the same JVM signature (foo$b$0(LDerived;)V):
|
||||
fun `foo$b$0`(d: Derived): kotlin.Unit
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (15, 5) Accidental override: The following declarations have the same JVM signature (access$foo$0(LDerived;)V):
|
||||
fun `access$foo$0`(d: Derived): kotlin.Unit
|
||||
fun foo(): kotlin.Unit
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (18, 9) Accidental override: The following declarations have the same JVM signature (getBar$b$1(LDerived;)I):
|
||||
fun `getBar$b$1`(d: Derived): kotlin.Int
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (18, 9) Accidental override: The following declarations have the same JVM signature (access$getBar$1(LDerived;)I):
|
||||
fun `access$getBar$1`(d: Derived): kotlin.Int
|
||||
fun <get-bar>(): kotlin.Int
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (19, 9) Accidental override: The following declarations have the same JVM signature (setBar$b$1(LDerived;I)V):
|
||||
fun `setBar$b$1`(d: Derived, i: kotlin.Int): kotlin.Unit
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (19, 9) Accidental override: The following declarations have the same JVM signature (access$setBar$1(LDerived;I)V):
|
||||
fun `access$setBar$1`(d: Derived, i: kotlin.Int): kotlin.Unit
|
||||
fun <set-bar>(<set-?>: kotlin.Int): kotlin.Unit
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (21, 5) Accidental override: The following declarations have the same JVM signature (getBaz$b$2(LDerived;)I):
|
||||
fun `getBaz$b$2`(d: Derived): kotlin.Int
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (21, 5) Accidental override: The following declarations have the same JVM signature (access$getBaz$2(LDerived;)I):
|
||||
fun `access$getBaz$2`(d: Derived): kotlin.Int
|
||||
fun <get-baz>(): kotlin.Int
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (23, 5) Accidental override: The following declarations have the same JVM signature (getBoo$b$3(LDerived;)I):
|
||||
fun `getBoo$b$3`(d: Derived): kotlin.Int
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (23, 5) Accidental override: The following declarations have the same JVM signature (access$getBoo$3(LDerived;)I):
|
||||
fun `access$getBoo$3`(d: Derived): kotlin.Int
|
||||
fun <get-boo>(): kotlin.Int
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (27, 9) Accidental override: The following declarations have the same JVM signature (setBar1$b$4(LDerived;I)V):
|
||||
fun `setBar1$b$4`(d: Derived, i: kotlin.Int): kotlin.Unit
|
||||
ERROR: compiler/testData/cli/jvm/syntheticAccessorSignatureClash.kt: (27, 9) Accidental override: The following declarations have the same JVM signature (access$setBar1$4(LDerived;I)V):
|
||||
fun `access$setBar1$4`(d: Derived, i: kotlin.Int): kotlin.Unit
|
||||
fun <set-bar1>(<set-?>: kotlin.Int): kotlin.Unit
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1,48 @@
|
||||
// This test checks that synthetic accessors generated by Kotlin compiler have names starting with "access$"
|
||||
// This is crucial for some JVM frameworks like Quasar which rely on the bytecode being similar to the one generated by javac
|
||||
// See https://youtrack.jetbrains.com/issue/KT-6870
|
||||
|
||||
class PrivateConstructor private() {
|
||||
class Nested { val a = PrivateConstructor() }
|
||||
}
|
||||
|
||||
class PrivatePropertyGet {
|
||||
private val x = 42
|
||||
|
||||
inner class Inner { val a = x }
|
||||
}
|
||||
|
||||
class PrivatePropertySet {
|
||||
private var x = "a"
|
||||
|
||||
inner class Inner { { x = "b" } }
|
||||
}
|
||||
|
||||
class PrivateMethod {
|
||||
private fun foo() = ""
|
||||
|
||||
inner class Inner { val a = foo() }
|
||||
}
|
||||
|
||||
fun check(klass: Class<*>) {
|
||||
for (method in klass.getDeclaredMethods()) {
|
||||
if (method.isSynthetic() && method.getName().startsWith("access$")) return
|
||||
}
|
||||
|
||||
throw AssertionError("No synthetic methods starting with 'access$' found in class $klass")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check(javaClass<PrivateConstructor>())
|
||||
check(javaClass<PrivatePropertyGet>())
|
||||
check(javaClass<PrivatePropertySet>())
|
||||
check(javaClass<PrivateMethod>())
|
||||
|
||||
// Also check that synthetic accessors really work
|
||||
PrivateConstructor.Nested()
|
||||
PrivatePropertyGet().Inner()
|
||||
PrivatePropertySet().Inner()
|
||||
PrivateMethod().Inner()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -5,4 +5,4 @@ class A {
|
||||
}
|
||||
// A and class object constructor call
|
||||
// 2 ALOAD 0
|
||||
// 1 synthetic getR
|
||||
// 1 synthetic access\$getR
|
||||
|
||||
Reference in New Issue
Block a user