JS: fix translation of delegated constructor call from secondary constructor when argument is a complex expression which translates to multiple statements. See KT-15357

This commit is contained in:
Alexey Andreev
2016-12-21 18:24:31 +03:00
parent 1ab78dffe5
commit 1ecd957981
9 changed files with 162 additions and 2 deletions
@@ -0,0 +1,19 @@
var log = ""
open class Base(val s: String)
class A(i: Int) : Base("O" + if (i == 23) {
log += "logged"
"K"
}
else {
"fail"
})
fun box(): String {
val result = A(23).s
if (result != "OK") return "fail: $result"
if (log != "logged") return "fail log: $log"
return "OK"
}
@@ -0,0 +1,46 @@
var log = ""
open class Base(val s: String)
class A(s: String) : Base(s) {
constructor(i: Int) : this("O" + if (i == 23) {
log += "logged1;"
"K"
}
else {
"fail"
})
constructor(i: Long) : this(if (i == 23L) {
log += "logged2;"
23
}
else {
42
})
}
class B : Base {
constructor(i: Int) : super("O" + if (i == 23) {
log += "logged3;"
"K"
}
else {
"fail"
})
}
fun box(): String {
var result = A(23).s
if (result != "OK") return "fail1: $result"
result = A(23L).s
if (result != "OK") return "fail2: $result"
result = B(23).s
if (result != "OK") return "fail3: $result"
if (log != "logged1;logged2;logged1;logged3;") return "fail log: $log"
return "OK"
}
@@ -0,0 +1,18 @@
public final class A {
public method <init>(p0: int): void
}
public class Base {
private final @org.jetbrains.annotations.NotNull field s: java.lang.String
public method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
}
public final class SuperConstructorCallWithComplexArgKt {
private static @org.jetbrains.annotations.NotNull field log: java.lang.String
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getLog(): java.lang.String
public final static method setLog(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
}
@@ -0,0 +1,25 @@
public final class A {
public method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public method <init>(p0: int): void
public method <init>(p0: long): void
}
public final class B {
public method <init>(p0: int): void
}
public class Base {
private final @org.jetbrains.annotations.NotNull field s: java.lang.String
public method <init>(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
}
public final class DelegateWithComplexExpressionKt {
private static @org.jetbrains.annotations.NotNull field log: java.lang.String
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method getLog(): java.lang.String
public final static method setLog(@org.jetbrains.annotations.NotNull p0: java.lang.String): void
}