mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Support secondary constructors in JVM backend
There is a lot of changes about closures calculating and generating. 1. As classes can have more than one constructor each of them should have closure arguments. 2. Captured variables set is the same for all of them. 3. Within constructors bodies/delegating calls closure parameters should be accessed through method arguments because fields may be not initialized yet.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package test;
|
||||
|
||||
public class secondaryConstructor {
|
||||
private final String x;
|
||||
private final String y;
|
||||
|
||||
public secondaryConstructor(String x, String y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public secondaryConstructor(String x) {
|
||||
this(x, "def_y");
|
||||
}
|
||||
|
||||
public secondaryConstructor() {
|
||||
this("def_x");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return x + "#" + y;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import test.secondaryConstructor;
|
||||
|
||||
class Child : secondaryConstructor {
|
||||
constructor(): super() {}
|
||||
constructor(x: String): super(x) {}
|
||||
constructor(x: String, y: String): super(x, y) {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c1 = Child().toString()
|
||||
if (c1 != "def_x#def_y") return "fail1: $c1"
|
||||
|
||||
val c2 = Child("abc").toString()
|
||||
if (c2 != "abc#def_y") return "fail2: $c2"
|
||||
|
||||
val c3 = Child("abc", "def").toString()
|
||||
if (c3 != "abc#def") return "fail3: $c3"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user