tests: Update external tests (1.1.2-dev-393)

This commit is contained in:
Ilya Matveev
2017-03-13 12:38:08 +03:00
committed by ilmat192
parent ac56fccb15
commit bc074e6d39
3178 changed files with 22396 additions and 696 deletions
@@ -0,0 +1,15 @@
internal class A(val result: Int) {
companion object {
fun foo(): Int = 1
val prop = 2
val C = 3
}
constructor() : this(foo() + prop + C)
}
fun box(): String {
val result = A().result
if (result != 6) return "fail: $result"
return "OK"
}
@@ -0,0 +1,16 @@
class A(val result: Int) {
object B {
fun bar(): Int = 4
val prop = 5
}
object C {
}
constructor() : this(B.bar() + B.prop)
}
fun box(): String {
val result = A().result
if (result != 9) return "fail: $result"
return "OK"
}
@@ -0,0 +1,35 @@
var sideEffects: String = ""
class A {
var prop: String = ""
init {
sideEffects += prop + "first"
}
constructor(x: String) {
prop = x
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int) {
prop += "$x#int"
sideEffects += "#fourth"
}
}
fun box(): String {
val a1 = A("abc")
if (a1.prop != "abc") return "fail1: ${a1.prop}"
if (sideEffects != "first#second#third") return "fail1-sideEffects: ${sideEffects}"
sideEffects = ""
val a2 = A(123)
if (a2.prop != "123#int") return "fail2: ${a2.prop}"
if (sideEffects != "first#second#fourth") return "fail2-sideEffects: ${sideEffects}"
return "OK"
}
@@ -0,0 +1,41 @@
internal var sideEffects: String = ""
internal class A {
var prop: String = ""
init {
sideEffects += prop + "first"
}
constructor() {}
constructor(x: String): this() {
prop = x
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int): this(x.toString()) {
prop += "#int"
sideEffects += "#fourth"
}
}
fun box(): String {
val a1 = A("abc")
if (a1.prop != "abc") return "fail1: ${a1.prop}"
if (sideEffects != "first#second#third") return "fail1-sideEffects: ${sideEffects}"
sideEffects = ""
val a2 = A(123)
if (a2.prop != "123#int") return "fail2: ${a2.prop}"
if (sideEffects != "first#second#third#fourth") return "fail2-sideEffects: ${sideEffects}"
sideEffects = ""
val a3 = A()
if (a3.prop != "") return "fail2: ${a3.prop}"
if (sideEffects != "first#second") return "fail3-sideEffects: ${sideEffects}"
return "OK"
}
@@ -0,0 +1,39 @@
var sideEffects: String = ""
class A() {
var prop: String = ""
init {
sideEffects += prop + "first"
}
constructor(x: String): this() {
prop = x
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int): this(x.toString()) {
prop += "#int"
sideEffects += "#fourth"
}
}
fun box(): String {
val a1 = A("abc")
if (a1.prop != "abc") return "fail1: ${a1.prop}"
if (sideEffects != "first#second#third") return "fail1-sideEffects: ${sideEffects}"
sideEffects = ""
val a2 = A(123)
if (a2.prop != "123#int") return "fail2: ${a2.prop}"
if (sideEffects != "first#second#third#fourth") return "fail2-sideEffects: ${sideEffects}"
sideEffects = ""
val a3 = A()
if (a3.prop != "") return "fail2: ${a3.prop}"
if (sideEffects != "first#second") return "fail3-sideEffects: ${sideEffects}"
return "OK"
}
@@ -0,0 +1,15 @@
fun box(): String {
val z = "K"
open class A(val x: String) {
constructor() : this("O")
val y: String
get() = z
}
class B : A()
val b = B()
return b.x + b.y
}
@@ -0,0 +1,11 @@
open class A(val result: String) {
constructor(x: Int = 11, y: Int = 22, z: Int = 33) : this("$x$y$z")
}
class B() : A(y = 44)
fun box(): String {
val result = B().result
if (result != "114433") return "fail: $result"
return "OK"
}
@@ -0,0 +1,11 @@
open class A(val result: String) {
constructor(x: Int, y: Int = 99) : this("$x$y")
}
class B(x: Int) : A(x)
fun box(): String {
val result = B(11).result
if (result != "1199") return "fail: $result"
return "OK"
}
@@ -0,0 +1,12 @@
open class A(val x: String, val z: String) {
constructor(z: String) : this("O", z)
}
class B(val y: String) : A("_")
fun box(): String {
val b = B("K")
val result = b.z + b.x + b.y
if (result != "_OK") return "fail: $result"
return "OK"
}
@@ -0,0 +1,35 @@
open class A(val x: String = "abc", val y: String = "efg") {
constructor(x: String, y: String, z: Int): this(x, y + "#" + z.toString())
override fun toString() = "$x#$y"
}
class B : A {
constructor(x: String, y: String, z: Int): super(x, y + z.toString())
constructor(x: String = "xyz", y: String = "123") : super(x, y)
constructor(x: Double): super(x.toString())
}
fun box(): String {
val a1 = A().toString()
if (a1 != "abc#efg") return "fail1: $a1"
val a2 = A("hij", "klm", 1).toString()
if (a2 != "hij#klm#1") return "fail2: $a2"
val a3 = A(x="xyz").toString()
if (a3 != "xyz#efg") return "fail3: $a3"
val b1 = B().toString()
if (b1 != "xyz#123") return "fail4: $b1"
val b2 = B("hij", "klm", 2).toString()
if (b2 != "hij#klm2") return "fail5: $b2"
val b3 = B(123.1).toString()
if (b3 != "123.1#efg") return "fail6: $b3"
val b4 = B(x="test").toString()
if (b4 != "test#123") return "fail7: $b4"
return "OK"
}
@@ -0,0 +1,53 @@
internal data class A1(val prop1: String) {
val prop2: String = "const2"
var prop3: String = ""
constructor(): this("default") {
prop3 = "empty"
}
constructor(x: Int): this(x.toString()) {
prop3 = "int"
}
fun f(): String = "$prop1#$prop2#$prop3"
}
internal class A2 private constructor() {
var prop1: String = ""
var prop2: String = "const2"
var prop3: String = ""
constructor(arg: String): this() {
prop1 = arg
}
constructor(x: Double): this() {
prop1 = "default"
prop3 = "empty"
}
constructor(x: Int): this(x.toString()) {
prop3 = "int"
}
fun f(): String = "$prop1#$prop2#$prop3"
}
fun box(): String {
val a1x = A1("asd")
if (a1x.f() != "asd#const2#") return "fail1: ${a1x.f()}"
if (a1x.toString() != "A1(prop1=asd)") return "fail1s: ${a1x.toString()}"
val a1y = A1()
if (a1y.f() != "default#const2#empty") return "fail2: ${a1y.f()}"
if (a1y.toString() != "A1(prop1=default)") return "fail2s: ${a1y.toString()}"
val a1z = A1(5)
if (a1z.f() != "5#const2#int") return "fail3: ${a1z.f()}"
if (a1z.toString() != "A1(prop1=5)") return "fail3s: ${a1z.toString()}"
val a2x = A2("asd")
if (a2x.f() != "asd#const2#") return "fail4: ${a2x.f()}"
val a2y = A2(123.0)
if (a2y.f() != "default#const2#empty") return "fail5: ${a2y.f()}"
val a2z = A2(5)
if (a2z.f() != "5#const2#int") return "fail6: ${a2z.f()}"
return "OK"
}
@@ -0,0 +1,34 @@
val global = "OK"
class A {
val prop: String
constructor(arg1: String = global) {
prop = arg1
}
constructor(arg1: String = global, arg2: Long) {
prop = "$arg1#$arg2"
}
constructor(arg1: String = global, argDouble: Double, arg3: Long = 1L) {
prop = "$arg1#$argDouble#$arg3"
}
}
fun box(): String {
val a1 = A()
if (a1.prop != "OK") return "fail1: ${a1.prop}"
val a2 = A("A")
if (a2.prop != "A") return "fail2: ${a2.prop}"
val a3 = A(arg2=123)
if (a3.prop != "OK#123") return "fail3: ${a3.prop}"
val a4 = A("A", arg2=123)
if (a4.prop != "A#123") return "fail4: ${a4.prop}"
val a5 = A(argDouble=23.1)
if (a5.prop != "OK#23.1#1") return "fail5: ${a5.prop}"
val a6 = A("A", argDouble=23.1)
if (a6.prop != "A#23.1#1") return "fail6: ${a6.prop}"
val a7 = A("A", arg3=2L, argDouble=23.1)
if (a7.prop != "A#23.1#2") return "fail7: ${a7.prop}"
return "OK"
}
@@ -0,0 +1,15 @@
var global = 0
fun sideEffect() = global++
class A(val x: String) {
constructor(y: Int = sideEffect(), z: (Int) -> Int = { it + sideEffect() }) : this("$y:${z(y)}") {}
}
fun box(): String {
var a = A()
if (a.x != "0:1") return "failed1: ${a.x}"
if (global != 2) return "failed2: ${global}"
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,9 @@
class A(val f: () -> Int) {
constructor() : this({ 23 })
}
fun box(): String {
val result = A().f()
if (result != 23) return "fail: $result"
return "OK"
}
@@ -0,0 +1,17 @@
internal interface A {
fun foo(): String
}
internal class B : A {
override fun foo() = "OK"
}
internal val global = B()
internal class C(x: Int) : A by global {
constructor(): this(1)
}
fun box(): String {
return C().foo()
}
@@ -0,0 +1,62 @@
enum class A1(val prop1: String) {
X("asd"),
Y() {
override fun f() = super.f() + "#Y"
},
Z(5);
val prop2: String = "const2"
var prop3: String = ""
constructor(): this("default") {
prop3 = "empty"
}
constructor(x: Int): this(x.toString()) {
prop3 = "int"
}
open fun f(): String = "$prop1#$prop2#$prop3"
}
enum class A2 {
X("asd"),
Y() {
override fun f() = super.f() + "#Y"
},
Z(5);
val prop1: String
val prop2: String = "const2"
var prop3: String = ""
constructor(arg: String) {
prop1 = arg
}
constructor() {
prop1 = "default"
prop3 = "empty"
}
constructor(x: Int): this(x.toString()) {
prop3 = "int"
}
open fun f(): String = "$prop1#$prop2#$prop3"
}
fun box(): String {
val a1x = A1.X
if (a1x.f() != "asd#const2#") return "fail1: ${a1x.f()}"
val a1y = A1.Y
if (a1y.f() != "default#const2#empty#Y") return "fail2: ${a1y.f()}"
val a1z = A1.Z
if (a1z.f() != "5#const2#int") return "fail3: ${a1z.f()}"
val a2x = A2.X
if (a2x.f() != "asd#const2#") return "fail4: ${a2x.f()}"
val a2y = A2.Y
if (a2y.f() != "default#const2#empty#Y") return "fail5: ${a2y.f()}"
val a2z = A2.Z
if (a2z.f() != "5#const2#int") return "fail6: ${a2z.f()}"
return "OK"
}
@@ -0,0 +1,23 @@
internal open class B<T>(val x: T, val y: T) {
constructor(x: T): this(x, x)
override fun toString() = "$x#$y"
}
internal class A : B<String> {
constructor(): super("default")
constructor(x: String): super(x, "default")
}
fun box(): String {
val b1 = B("1", "2").toString()
if (b1 != "1#2") return "fail1: $b1"
val b2 = B("abc").toString()
if (b2 != "abc#abc") return "fail2: $b2"
val a1 = A().toString()
if (a1 != "default#default") return "fail3: $a1"
val a2 = A("xyz").toString()
if (a2 != "xyz#default") return "fail4: $a2"
return "OK"
}
@@ -0,0 +1,79 @@
class Outer {
val outerProp: String
constructor(x: String) {
outerProp = x
}
var sideEffects = ""
inner class A1() {
var prop: String = ""
init {
sideEffects += outerProp + "#" + prop + "first"
}
constructor(x: String): this() {
prop = x + "#${outerProp}"
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int): this(x.toString() + "#" + outerProp) {
prop += "#int"
sideEffects += "#fourth"
}
}
inner class A2 {
var prop: String = ""
init {
sideEffects += outerProp + "#" + prop + "first"
}
constructor(x: String) {
prop = x + "#$outerProp"
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int) {
prop += "$x#$outerProp#int"
sideEffects += "#fourth"
}
}
}
fun box(): String {
val outer1 = Outer("propValue1")
val a1 = outer1.A1("abc")
if (a1.prop != "abc#propValue1") return "fail1: ${a1.prop}"
if (outer1.sideEffects != "propValue1#first#second#third") return "fail1-sideEffects: ${outer1.sideEffects}"
val outer2 = Outer("propValue2")
val a2 = outer2.A1(123)
if (a2.prop != "123#propValue2#propValue2#int") return "fail2: ${a2.prop}"
if (outer2.sideEffects != "propValue2#first#second#third#fourth") return "fail2-sideEffects: ${outer2.sideEffects}"
val outer3 = Outer("propValue3")
val a3 = outer3.A1()
if (a3.prop != "") return "fail2: ${a3.prop}"
if (outer3.sideEffects != "propValue3#first#second") return "fail3-sideEffects: ${outer3.sideEffects}"
val outer4 = Outer("propValue4")
val a4 = outer4.A2("abc")
if (a4.prop != "abc#propValue4") return "fail4: ${a4.prop}"
if (outer4.sideEffects != "propValue4#first#second#third") return "fail4-sideEffects: ${outer4.sideEffects}"
val outer5 = Outer("propValue5")
val a5 = outer5.A2(123)
if (a5.prop != "123#propValue5#int") return "fail5: ${a5.prop}"
if (outer5.sideEffects != "propValue5#first#second#fourth") return "fail5-sideEffects: ${outer5.sideEffects}"
return "OK"
}
@@ -0,0 +1,66 @@
class Outer {
val outerProp: String
constructor(x: String) {
outerProp = x
}
var sideEffects = ""
abstract inner class A1 {
var parentProp: String = ""
init {
sideEffects += outerProp + "#" + parentProp + "first"
}
protected constructor(x: String) {
parentProp = x + "#${outerProp}"
sideEffects += "#second#"
}
init {
sideEffects += parentProp + "#third"
}
protected constructor(x: Int): this(x.toString() + "#" + outerProp) {
parentProp += "#int"
sideEffects += "fourth#"
}
}
inner class A2 : A1 {
var prop: String = ""
init {
sideEffects += outerProp + "#" + prop + "fifth"
}
constructor(x: String): super(x + "#" + outerProp) {
prop = x + "#$outerProp"
sideEffects += "#sixth"
}
init {
sideEffects += prop + "#seventh"
}
constructor(x: Int): super(x + 1) {
prop += "$x#$outerProp#int"
sideEffects += "#eighth"
}
}
}
fun box(): String {
val outer1 = Outer("propValue1")
val a1 = outer1.A2("abc")
if (a1.parentProp != "abc#propValue1#propValue1") return "fail1: ${a1.parentProp}"
if (a1.prop != "abc#propValue1") return "fail2: ${a1.prop}"
if (outer1.sideEffects != "propValue1#first#third#second#propValue1#fifth#seventh#sixth") return "fail1-sideEffects: ${outer1.sideEffects}"
val outer2 = Outer("propValue2")
val a2 = outer2.A2(123)
if (a2.parentProp != "124#propValue2#propValue2#int") return "fail3: ${a2.parentProp}"
if (a2.prop != "123#propValue2#int") return "fail4: ${a2.prop}"
if (outer2.sideEffects != "propValue2#first#third#second#fourth#propValue2#fifth#seventh#eighth") return "fail2-sideEffects: ${outer2.sideEffects}"
return "OK"
}
@@ -0,0 +1,77 @@
open class C(val grandParentProp: String)
fun box(): String {
var sideEffects: String = ""
var parentSideEffects: String = ""
val justForUsageInClosure = 7
val justForUsageInParentClosure = "parentCaptured"
abstract class B : C {
val parentProp: String
init {
sideEffects += "minus-one#"
parentSideEffects += "1"
}
protected constructor(arg: Int): super(justForUsageInParentClosure) {
parentProp = (arg).toString()
sideEffects += "0.5#"
parentSideEffects += "#" + justForUsageInParentClosure
}
protected constructor(arg1: Int, arg2: Int): super(justForUsageInParentClosure) {
parentProp = (arg1 + arg2).toString()
sideEffects += "0.7#"
parentSideEffects += "#3"
}
init {
sideEffects += "zero#"
parentSideEffects += "#4"
}
}
class A : B {
var prop: String = ""
init {
sideEffects += prop + "first"
}
constructor(x1: Int, x2: Int): super(x1, x2) {
prop = x1.toString()
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int): super(justForUsageInClosure + x) {
prop += "${x}#int"
sideEffects += "#fourth"
}
constructor(): this(justForUsageInClosure) {
sideEffects += "#fifth"
}
override fun toString() = "$prop#$parentProp#$grandParentProp"
}
val a1 = A(5, 10).toString()
if (a1 != "5#15#parentCaptured") return "fail1: $a1"
if (sideEffects != "minus-one#zero#0.7#first#second#third") return "fail2: ${sideEffects}"
if (parentSideEffects != "1#4#3") return "fail3: ${parentSideEffects}"
sideEffects = ""
parentSideEffects = ""
val a2 = A(123).toString()
if (a2 != "123#int#130#parentCaptured") return "fail1: $a2"
if (sideEffects != "minus-one#zero#0.5#first#second#fourth") return "fail4: ${sideEffects}"
if (parentSideEffects != "1#4#parentCaptured") return "fail5: ${parentSideEffects}"
sideEffects = ""
parentSideEffects = ""
val a3 = A().toString()
if (a3 != "7#int#14#parentCaptured") return "fail6: $a3"
if (sideEffects != "minus-one#zero#0.5#first#second#fourth#fifth") return "fail7: ${sideEffects}"
if (parentSideEffects != "1#4#parentCaptured") return "fail8: ${parentSideEffects}"
return "OK"
}
@@ -0,0 +1,53 @@
var sideEffects: String = ""
abstract class B protected constructor(val arg: Int) {
val parentProp: String
init {
sideEffects += "zero#"
parentProp = arg.toString()
}
}
class A(x: Boolean) : B(if (x) 1 else 2) {
var prop: String = ""
init {
sideEffects += prop + "first"
}
constructor(x: String): this(x == "abc") {
prop = x
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int): this(x < 0) {
prop += "${x}#int"
sideEffects += "#fourth"
}
}
fun box(): String {
val a1 = A("abc")
if (a1.prop != "abc") return "fail0: ${a1.prop}"
if (a1.parentProp != "1") return "fail1: ${a1.parentProp}"
if (a1.arg != 1) return "fail1': ${a1.arg}"
if (sideEffects != "zero#first#second#third") return "fail2: ${sideEffects}"
sideEffects = ""
val a2 = A(123)
if (a2.prop != "123#int") return "fail3: ${a2.prop}"
if (a2.parentProp != "2") return "fail4: ${a2.parentProp}"
if (a2.arg != 2) return "fail5': ${a2.arg}"
if (sideEffects != "zero#first#second#fourth") return "fail6: ${sideEffects}"
sideEffects = ""
val a3 = A(false)
if (a3.prop != "") return "fail7: ${a3.prop}"
if (a3.parentProp != "2") return "fail8: ${a3.parentProp}"
if (a3.arg != 2) return "fail9': ${a3.arg}"
if (sideEffects != "zero#first#second") return "fail10: ${sideEffects}"
return "OK"
}
@@ -0,0 +1,64 @@
var sideEffects: String = ""
internal abstract class B {
val parentProp: String
init {
sideEffects += "minus-one#"
}
protected constructor(arg: Int) {
parentProp = (arg).toString()
sideEffects += "0.5#"
}
protected constructor(arg1: Int, arg2: Int) {
parentProp = (arg1 + arg2).toString()
sideEffects += "0.7#"
}
init {
sideEffects += "zero#"
}
}
internal class A : B {
var prop: String = ""
init {
sideEffects += prop + "first"
}
constructor(x1: Int, x2: Int): super(x1, x2) {
prop = x1.toString()
sideEffects += "#third"
}
init {
sideEffects += prop + "#second"
}
constructor(x: Int): super(3 + x) {
prop += "${x}#int"
sideEffects += "#fourth"
}
constructor(): this(7) {
sideEffects += "#fifth"
}
}
fun box(): String {
val a1 = A(5, 10)
if (a1.prop != "5") return "fail0: ${a1.prop}"
if (a1.parentProp != "15") return "fail1: ${a1.parentProp}"
if (sideEffects != "minus-one#zero#0.7#first#second#third") return "fail2: ${sideEffects}"
sideEffects = ""
val a2 = A(123)
if (a2.prop != "123#int") return "fail3: ${a2.prop}"
if (a2.parentProp != "126") return "fail4: ${a2.parentProp}"
if (sideEffects != "minus-one#zero#0.5#first#second#fourth") return "fail5: ${sideEffects}"
sideEffects = ""
val a3 = A()
if (a3.prop != "7#int") return "fail6: ${a3.prop}"
if (a3.parentProp != "10") return "fail7: ${a3.parentProp}"
if (sideEffects != "minus-one#zero#0.5#first#second#fourth#fifth") return "fail8: ${sideEffects}"
return "OK"
}
@@ -0,0 +1,31 @@
fun join(x: Array<out String>): String {
var result = ""
for (i in x) {
result += i
result += "#"
}
return result
}
open class B {
val parentProp: String
constructor(vararg x: String) {
parentProp = join(x)
}
}
class A : B {
val prop: String
constructor(vararg x: String): super("0", *x, "4") {
prop = join(x)
}
}
fun box(): String {
val a1 = A("1", "2", "3")
if (a1.prop != "1#2#3#") return "fail1: ${a1.prop}"
if (a1.parentProp != "0#1#2#3#4#") return "fail2: ${a1.parentProp}"
return "OK"
}
@@ -0,0 +1,37 @@
// TARGET_BACKEND: JVM
// FILE: WithGenerics.java
class WithGenerics {
public static String foo1() {
A<Double> x = new A<Double>("OK");
return x.toString();
}
public static String foo2() {
A<Integer> x = new A<Integer>(123);
return x.toString();
}
}
// FILE: WithGenerics.kt
open class A<T> {
val prop: String
constructor(x: String) {
prop = x
}
constructor(x: T) {
prop = x.toString()
}
override fun toString() = prop
}
fun box(): String {
val a1 = WithGenerics.foo1()
if (a1 != "OK") return "fail1: $a1"
val a2 = WithGenerics.foo2()
if (a2 != "123") return "fail2: $a2"
return "OK"
}
@@ -0,0 +1,24 @@
// TODO enable for JS backend too when KT-14549 will be fixed
// IGNORE_BACKEND: JS
inline fun run(block: () -> Unit) = block()
class A {
val prop: Int
constructor(arg: Boolean) {
if (arg) {
prop = 1
run { return }
throw RuntimeException("fail 0")
}
prop = 2
}
}
fun box(): String {
val a1 = A(true)
if (a1.prop != 1) return "fail1: ${a1.prop}"
val a2 = A(false)
if (a2.prop != 2) return "fail2: ${a2.prop}"
return "OK"
}
@@ -0,0 +1,41 @@
// TARGET_BACKEND: JVM
// FILE: WithPrimary.java
class WithPrimary {
public static A test1() {
return new A("123", "abc");
}
public static A test2() {
return new A();
}
public static A test3() {
return new A("123", 456);
}
public static A test4() {
return new A(1.0);
}
}
// FILE: WithPrimary.kt
class A(val x: String = "def_x", val y: String = "1") {
constructor(x: String, y: Int): this(x, y.toString()) {}
constructor(x: Double): this(x.toString(), "def_y") {}
override fun toString() = "$x#$y"
}
fun box(): String {
val test1 = WithPrimary.test1().toString()
if (test1 != "123#abc") return "fail1: $test1"
val test2 = WithPrimary.test2().toString()
if (test2 != "def_x#1") return "fail2: $test2"
val test3 = WithPrimary.test3().toString()
if (test3 != "123#456") return "fail3: $test3"
val test4 = WithPrimary.test4().toString()
if (test4 != "1.0#def_y") return "fail4: $test4"
return "OK"
}
@@ -0,0 +1,18 @@
class A {
val prop: Int
constructor(arg: Boolean) {
if (arg) {
prop = 1
return
}
prop = 2
}
}
fun box(): String {
val a1 = A(true)
if (a1.prop != 1) return "fail1: ${a1.prop}"
val a2 = A(false)
if (a2.prop != 2) return "fail2: ${a2.prop}"
return "OK"
}
@@ -0,0 +1,18 @@
class A {
val prop: Int
constructor(arg: Boolean) {
if (arg) {
prop = 1
return Unit
}
prop = 2
}
}
fun box(): String {
val a1 = A(true)
if (a1.prop != 1) return "fail1: ${a1.prop}"
val a2 = A(false)
if (a2.prop != 2) return "fail2: ${a2.prop}"
return "OK"
}
@@ -0,0 +1,34 @@
// TARGET_BACKEND: JVM
// FILE: WithVarargs.java
public class WithVarargs {
public static String foo() {
return new A("1", "2", "3").getProp();
}
}
// FILE: withVarargs.kt
fun join(x: Array<out String>): String {
var result = ""
for (i in x) {
result += i
result += "#"
}
return result
}
class A {
val prop: String
constructor(vararg x: String) {
prop = join(x)
}
}
fun box(): String {
val a1 = WithVarargs.foo()
if (a1 != "1#2#3#") return "fail1: ${a1}"
return "OK"
}
@@ -0,0 +1,41 @@
// TARGET_BACKEND: JVM
// FILE: WithoutPrimary.java
class WithoutPrimary {
public static A test1() {
return new A("123", "abc");
}
public static A test3() {
return new A("123", 456);
}
public static A test4() {
return new A(1.0);
}
}
// FILE: WithoutPrimary.kt
class A {
val x: String
val y: String
constructor(x: String, y: String) {
this.x = x
this.y = y
}
constructor(x: String = "def_x", y: Int = 1): this(x, y.toString()) {}
constructor(x: Double): this(x.toString(), "def_y") {}
override fun toString() = "$x#$y"
}
fun box(): String {
val test1 = WithoutPrimary.test1().toString()
if (test1 != "123#abc") return "fail1: $test1"
val test3 = WithoutPrimary.test3().toString()
if (test3 != "123#456") return "fail3: $test3"
val test4 = WithoutPrimary.test4().toString()
if (test4 != "1.0#def_y") return "fail4: $test4"
return "OK"
}