mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 15:53:37 +00:00
Inner class constructors should use the argument instead of reading outer `this` from a field because if such an access happens before a delegating constructor call, e.g. when evaluating an argument, a JVM bytecode validation error will be thrown. (The only operation on `this` allowed before a delegating constructor call is SETFIELD, and only if the field in question is declared in the same class.)
23 lines
476 B
Kotlin
Vendored
23 lines
476 B
Kotlin
Vendored
// TARGET_BACKEND: JVM
|
|
// FILE: JavaClass.java
|
|
|
|
public abstract class JavaClass {
|
|
public abstract InnerClass onCreateInner();
|
|
|
|
public class InnerClass {
|
|
|
|
}
|
|
}
|
|
|
|
// FILE: Kotlin.kt
|
|
|
|
public class MyWallpaperService : JavaClass() {
|
|
override fun onCreateInner(): JavaClass.InnerClass = MyEngine()
|
|
|
|
private inner class MyEngine : JavaClass.InnerClass()
|
|
}
|
|
|
|
fun box(): String {
|
|
return if (MyWallpaperService().onCreateInner() != null) return "OK" else "fail"
|
|
}
|