Files
kotlin-fork/compiler/testData/codegen/box/syntheticAccessors/syntheticAccessorNames.kt
T
Ilya Matveev a5e4e0284e Mute some box tests for native backend
This patch mutes the following test categories:
   * Tests with java dependencies (System class,
     java stdlib, jvm-oriented annotations etc).
   * Coroutines tests.
   * Reflection tests.
   * Tests with an inheritance from the standard
     collections.
2017-03-10 19:59:37 +03:00

47 lines
1.2 KiB
Kotlin
Vendored

// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// WITH_RUNTIME
// 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 PrivatePropertyGet {
private val x = 42
inner class Inner { val a = x }
}
class PrivatePropertySet {
private var x = "a"
inner class Inner { init { 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(PrivatePropertyGet::class.java)
check(PrivatePropertySet::class.java)
check(PrivateMethod::class.java)
// Also check that synthetic accessors really work
PrivatePropertyGet().Inner()
PrivatePropertySet().Inner()
PrivateMethod().Inner()
return "OK"
}