tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
class A {
|
||||
companion object {
|
||||
var xi = 0
|
||||
var xin : Int? = 0
|
||||
var xinn : Int? = null
|
||||
|
||||
var xl = 0.toLong()
|
||||
var xln : Long? = 0.toLong()
|
||||
var xlnn : Long? = null
|
||||
|
||||
var xb = 0.toByte()
|
||||
var xbn : Byte? = 0.toByte()
|
||||
var xbnn : Byte? = null
|
||||
|
||||
var xf = 0.toFloat()
|
||||
var xfn : Float? = 0.toFloat()
|
||||
var xfnn : Float? = null
|
||||
|
||||
var xd = 0.toDouble()
|
||||
var xdn : Double? = 0.toDouble()
|
||||
var xdnn : Double? = null
|
||||
|
||||
var xs = 0.toShort()
|
||||
var xsn : Short? = 0.toShort()
|
||||
var xsnn : Short? = null
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: CompanionInitialization.java
|
||||
|
||||
public class CompanionInitialization {
|
||||
|
||||
public static Object getCompanion() {
|
||||
return ConcreteWithStatic.Companion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: CompanionInitialization.kt
|
||||
|
||||
interface IStatic
|
||||
|
||||
open class Static(x: IStatic) {
|
||||
fun doSth() {
|
||||
}
|
||||
}
|
||||
|
||||
class ConcreteWithStatic : IStatic {
|
||||
companion object : Static(ConcreteWithStatic())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
ConcreteWithStatic.doSth()
|
||||
|
||||
val companion: Any? = CompanionInitialization.getCompanion()
|
||||
if (companion == null) return "fail 1"
|
||||
if (companion != ConcreteWithStatic) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class TestPackage {
|
||||
val OK = "OK"
|
||||
}
|
||||
|
||||
fun box(): String = TestPackage().OK
|
||||
@@ -0,0 +1,11 @@
|
||||
class C() {
|
||||
companion object {
|
||||
fun create() = C()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C.create()
|
||||
return if (c is C) "OK" else "fail"
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun Any.foo() = 1
|
||||
|
||||
class A {
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box() = if (A.foo() == 1) "OK" else "fail"
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
var global = 0;
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
init {
|
||||
global = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (global != 0) {
|
||||
return "fail1: global = $global"
|
||||
}
|
||||
|
||||
val c = C()
|
||||
if (global == 1) return "OK" else return "fail2: global = $global"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class A() {
|
||||
companion object {
|
||||
val value = 10
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = if (A.value == 10) "OK" else "Fail ${A.value}"
|
||||
@@ -0,0 +1,12 @@
|
||||
// EA-38323 - Illegal field modifiers in class: classObject field in C must be static and final
|
||||
|
||||
interface C {
|
||||
companion object {
|
||||
public val FOO: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return C.FOO
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
companion object {
|
||||
fun values() = "O"
|
||||
fun valueOf() = "K"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A.values() + A.valueOf()
|
||||
@@ -0,0 +1,9 @@
|
||||
// TODO: Enable for JS when it supports Java class library.
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
class SomeClass { companion object }
|
||||
|
||||
fun box() =
|
||||
if ((SomeClass.toString() as java.lang.String).matches("SomeClass\\\$Companion@[0-9a-fA-F]+"))
|
||||
"OK"
|
||||
else
|
||||
"Fail: $SomeClass"
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class C() {
|
||||
companion object {
|
||||
private fun <T> create() = C()
|
||||
}
|
||||
|
||||
class ZZZ {
|
||||
val c = C.create<String>()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
C.ZZZ().c
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
open class Test {
|
||||
companion object {
|
||||
fun testStatic(ic: InnerClass): NotInnerClass = NotInnerClass(ic.value)
|
||||
}
|
||||
|
||||
fun test(): InnerClass = InnerClass(150)
|
||||
|
||||
inner open class InnerClass(val value: Int)
|
||||
open class NotInnerClass(val value: Int)
|
||||
}
|
||||
|
||||
fun box() = if (Test.testStatic(Test().test()).value == 150) "OK" else "FAIL"
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
class A {
|
||||
private val p: Int
|
||||
get() = 4
|
||||
|
||||
companion object B {
|
||||
val p: Int
|
||||
get() = 6
|
||||
}
|
||||
|
||||
fun a() = p + B.p
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (A().a() != 10) return "Fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
interface Trait1 {
|
||||
fun foo() : String
|
||||
}
|
||||
|
||||
interface Trait2 {
|
||||
fun bar() : String
|
||||
}
|
||||
|
||||
class T1 : Trait1{
|
||||
override fun foo() = "aaa"
|
||||
}
|
||||
|
||||
class T2 : Trait2{
|
||||
override fun bar() = "bbb"
|
||||
}
|
||||
|
||||
class C(a:Trait1, b:Trait2) : Trait1 by a, Trait2 by b
|
||||
|
||||
fun box() : String {
|
||||
val c = C(T1(),T2())
|
||||
if(c.foo() != "aaa") return "fail"
|
||||
if(c.bar() != "bbb") return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
interface One {
|
||||
public open fun foo() : Int
|
||||
public open fun faz() : Int = 10
|
||||
}
|
||||
interface Two {
|
||||
public open fun foo() : Int
|
||||
public open fun quux() : Int = 100
|
||||
}
|
||||
|
||||
class OneImpl : One {
|
||||
public override fun foo() = 1
|
||||
}
|
||||
class TwoImpl : Two {
|
||||
public override fun foo() = 2
|
||||
}
|
||||
|
||||
class Test2(a : One, b : Two) : Two by b, One by a {
|
||||
public override fun foo() = 0
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var t2 = Test2(OneImpl(), TwoImpl())
|
||||
if (t2.foo() != 0)
|
||||
return "Fail #1"
|
||||
if (t2.faz() != 10)
|
||||
return "Fail #2"
|
||||
if (t2.quux() != 100)
|
||||
return "Fail #3"
|
||||
if (t2 !is One)
|
||||
return "Fail #4"
|
||||
if (t2 !is Two)
|
||||
return "Fail #5"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
interface First {
|
||||
public open fun foo() : Int
|
||||
}
|
||||
|
||||
interface Second : First {
|
||||
public open fun bar() : Int
|
||||
}
|
||||
|
||||
class Impl : Second {
|
||||
public override fun foo() = 1
|
||||
public override fun bar() = 2
|
||||
}
|
||||
|
||||
class Test(s : Second) : Second by s {}
|
||||
|
||||
fun box() : String {
|
||||
var t = Test(Impl())
|
||||
if (t.foo() != 1)
|
||||
return "Fail #1"
|
||||
if (t.bar() != 2)
|
||||
return "Fail #2"
|
||||
if (t !is First)
|
||||
return "Fail #3"
|
||||
if (t !is Second)
|
||||
return "Fail #4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
interface A<T> {
|
||||
fun foo(t: T): String
|
||||
}
|
||||
|
||||
class Derived(a: A<Int>) : A<Int> by a
|
||||
|
||||
fun box(): String {
|
||||
val o = object : A<Int> {
|
||||
override fun foo(t: Int) = if (t == 42) "OK" else "Fail $t"
|
||||
}
|
||||
return Derived(o).foo(42)
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
interface A<T: Number> {
|
||||
fun foo(t: T): String
|
||||
}
|
||||
|
||||
class Derived(a: A<Int>) : A<Int> by a
|
||||
|
||||
fun box(): String {
|
||||
val o = object : A<Int> {
|
||||
override fun foo(t: Int) = if (t == 42) "OK" else "Fail $t"
|
||||
}
|
||||
return Derived(o).foo(42)
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
interface A<T, U> {
|
||||
fun foo(t: T, u: U): String
|
||||
}
|
||||
|
||||
class Derived(a: A<Long, Int>) : A<Long, Int> by a
|
||||
|
||||
fun box(): String {
|
||||
val o = object : A<Long, Int> {
|
||||
override fun foo(t: Long, u: Int) = if (t == u.toLong()) "OK" else "Fail $t $u"
|
||||
}
|
||||
return Derived(o).foo(42, 42)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Enable for JS when it supports Java class library.
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
class TestJava(r : Runnable) : Runnable by r {}
|
||||
class TestRunnable() : Runnable {
|
||||
public override fun run() = System.out.println("foobar")
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var del = TestJava(TestRunnable())
|
||||
del.run()
|
||||
if (del !is Runnable)
|
||||
return "Fail #1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package test
|
||||
|
||||
interface TextField {
|
||||
fun getText(): String
|
||||
}
|
||||
|
||||
interface InputTextField : TextField {
|
||||
fun setText(text: String)
|
||||
}
|
||||
|
||||
interface MooableTextField : InputTextField {
|
||||
fun moo(a: Int, b: Int, c: Int): Int
|
||||
}
|
||||
|
||||
class SimpleTextField : MooableTextField {
|
||||
private var text2 = ""
|
||||
override fun getText() = text2
|
||||
override fun setText(text: String) {
|
||||
this.text2 = text
|
||||
}
|
||||
override fun moo(a: Int, b: Int, c: Int) = a + b + c
|
||||
}
|
||||
|
||||
class TextFieldWrapper(textField: MooableTextField) : MooableTextField by textField
|
||||
|
||||
fun box() : String {
|
||||
val textField = TextFieldWrapper(SimpleTextField())
|
||||
textField.setText("hello world!")
|
||||
|
||||
if (!textField.getText().equals("hello world!")) return "FAIL #!1"
|
||||
if (textField.moo(1,2,3) != 6) return "FAIL #2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class GameError(msg: String): Exception(msg) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val e = GameError("foo")
|
||||
return if (e.message == "foo") "OK" else "fail"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class C() {
|
||||
companion object Foo
|
||||
}
|
||||
|
||||
fun C.Foo.create() = 3
|
||||
|
||||
fun box(): String {
|
||||
val c1 = C.Foo.create()
|
||||
val c2 = C.create()
|
||||
return if (c1 == 3 && c2 == 3) "OK" else "fail"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
open class Base() {
|
||||
fun n(n : Int) : Int = n + 1
|
||||
}
|
||||
|
||||
interface Abstract {}
|
||||
|
||||
class Derived1() : Base(), Abstract {}
|
||||
class Derived2() : Abstract, Base() {}
|
||||
|
||||
fun test(s : Base) : Boolean = s.n(238) == 239
|
||||
|
||||
fun box() : String {
|
||||
if (!test(Base())) return "Fail #1"
|
||||
if (!test(Derived1())) return "Fail #2"
|
||||
if (!test(Derived2())) return "Fail #3"
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// See KT-12865
|
||||
|
||||
package foo
|
||||
|
||||
abstract class Base {
|
||||
val x = 23
|
||||
}
|
||||
|
||||
class Derived : Base(), Comparable<Derived> {
|
||||
val y = 42
|
||||
override fun compareTo(other: Derived): Int {
|
||||
throw UnsupportedOperationException("not implemented")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = Derived()
|
||||
if (b.x != 23) return "fail1: ${b.x}"
|
||||
if (b.y != 42) return "fail2: ${b.y}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
|
||||
interface A : Set<String>
|
||||
|
||||
class B : A, HashSet<String>()
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
b.add("OK")
|
||||
return b.iterator().next()
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Changed when traits were introduced. May not make sense any more
|
||||
|
||||
open class X(val x : Int) {}
|
||||
interface Y {
|
||||
abstract val y : Int
|
||||
}
|
||||
|
||||
class YImpl(override val y : Int) : Y {}
|
||||
|
||||
class Point(x : Int, yy : Int) : X(x) , Y {
|
||||
override val y : Int = yy
|
||||
}
|
||||
|
||||
interface Abstract {}
|
||||
|
||||
class P1(x : Int, yy : Y) : Abstract, X(x), Y by yy {}
|
||||
class P2(x : Int, yy : Y) : X(x), Abstract, Y by yy {}
|
||||
class P3(x : Int, yy : Y) : X(x), Y by yy, Abstract {}
|
||||
class P4(x : Int, yy : Y) : Y by yy, Abstract, X(x) {}
|
||||
|
||||
fun box() : String {
|
||||
if (X(239).x != 239) return "FAIL #1"
|
||||
if (YImpl(239).y != 239) return "FAIL #2"
|
||||
|
||||
val p = Point(240, -1)
|
||||
if (p.x + p.y != 239) return "FAIL #3"
|
||||
|
||||
val y = YImpl(-1)
|
||||
val p1 = P1(240, y)
|
||||
if (p1.x + p1.y != 239) return "FAIL #4"
|
||||
val p2 = P2(240, y)
|
||||
if (p2.x + p2.y != 239) return "FAIL #5"
|
||||
|
||||
val p3 = P3(240, y)
|
||||
if (p3.x + p3.y != 239) return "FAIL #6"
|
||||
|
||||
val p4 = P4(240, y)
|
||||
if (p4.x + p4.y != 239) return "FAIL #7"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Outer() {
|
||||
open inner class InnerBase() {
|
||||
}
|
||||
|
||||
inner class InnerDerived(): InnerBase() {
|
||||
}
|
||||
|
||||
public val foo: InnerBase? = InnerDerived()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val o = Outer()
|
||||
return if (o.foo === null) "fail" else "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
open class Foo {
|
||||
fun xyzzy(): String = "xyzzy"
|
||||
}
|
||||
|
||||
class Bar(): Foo() {
|
||||
fun test(): String = xyzzy()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val bar = Bar()
|
||||
val f = bar.test()
|
||||
return if (f == "xyzzy") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class C() {
|
||||
public var f: Int
|
||||
|
||||
init {
|
||||
f = 610
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
if (c.f != 610) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
class World() {
|
||||
public val items: ArrayList<Item> = ArrayList<Item>()
|
||||
|
||||
inner class Item() {
|
||||
init {
|
||||
items.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
val foo = Item()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val w = World()
|
||||
if (w.items.size != 1) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
open class A(val value: String) {
|
||||
inner class B(val s: String) {
|
||||
val result = value + "_" + s
|
||||
}
|
||||
}
|
||||
|
||||
class C : A("fromC") {
|
||||
fun classReceiver() = B("OK")
|
||||
fun superReceiver() = super.B("OK")
|
||||
|
||||
fun newAReceiver() = A("fromA").B("OK")
|
||||
fun aReceiver(): B {
|
||||
val a = A("fromA")
|
||||
return a.B("OK")
|
||||
}
|
||||
|
||||
fun A.extReceiver() = this.B("OK")
|
||||
fun extReceiver() = A("fromA").extReceiver()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val receiver = C()
|
||||
var result = receiver.classReceiver().result
|
||||
if (result != "fromC_OK") return "fail 1: $result"
|
||||
|
||||
result = receiver.superReceiver().result
|
||||
if (result != "fromC_OK") return "fail 2: $result"
|
||||
|
||||
|
||||
result = receiver.aReceiver().result
|
||||
if (result != "fromA_OK") return "fail 3: $result"
|
||||
|
||||
result = receiver.newAReceiver().result
|
||||
if (result != "fromA_OK") return "fail 3: $result"
|
||||
|
||||
result = receiver.extReceiver().result
|
||||
if (result != "fromA_OK") return "fail 3: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
open class A(val value: String) {
|
||||
inner class B(val s: String) {
|
||||
val result = value + "_" + s
|
||||
}
|
||||
}
|
||||
|
||||
class C : A("fromC") {
|
||||
|
||||
inner class X: A("fromX") {
|
||||
fun classReceiver() = B("OK")
|
||||
fun superReceiver() = super.B("OK")
|
||||
fun superXReceiver() = super@X.B("OK")
|
||||
fun superXCastReceiver() = (this@X as A).B("OK")
|
||||
|
||||
fun superCReceiver() = super@C.B("OK")
|
||||
fun superCCastReceiver() = (this@C as A).B("OK")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val receiver = C().X()
|
||||
var result = receiver.classReceiver().result
|
||||
if (result != "fromX_OK") return "fail 1: $result"
|
||||
|
||||
result = receiver.superReceiver().result
|
||||
if (result != "fromX_OK") return "fail 2: $result"
|
||||
|
||||
result = receiver.superXReceiver().result
|
||||
if (result != "fromX_OK") return "fail 3: $result"
|
||||
|
||||
result = receiver.superXCastReceiver().result
|
||||
if (result != "fromX_OK") return "fail 4: $result"
|
||||
|
||||
|
||||
result = receiver.superCReceiver().result
|
||||
if (result != "fromC_OK") return "fail 3: $result"
|
||||
|
||||
result = receiver.superCCastReceiver().result
|
||||
if (result != "fromC_OK") return "fail 4: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
class C(val value: String = "C") {
|
||||
|
||||
inner class B(val s: String) {
|
||||
val result = value + "_" + s
|
||||
}
|
||||
|
||||
fun classReceiver() = B("OK")
|
||||
|
||||
fun newCReceiver() = C("newC").B("OK")
|
||||
fun cReceiver(): B {
|
||||
val c = C("newC")
|
||||
return c.B("OK")
|
||||
}
|
||||
|
||||
fun C.extReceiver1() = this.B("OK")
|
||||
fun extReceiver() = C("newC").extReceiver1()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val receiver = C()
|
||||
var result = receiver.classReceiver().result
|
||||
if (result != "C_OK") return "fail 1: $result"
|
||||
|
||||
result = receiver.cReceiver().result
|
||||
if (result != "newC_OK") return "fail 3: $result"
|
||||
|
||||
result = receiver.newCReceiver().result
|
||||
if (result != "newC_OK") return "fail 3: $result"
|
||||
|
||||
result = receiver.extReceiver().result
|
||||
if (result != "newC_OK") return "fail 3: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
open class A() {
|
||||
open inner class InnerA
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
inner class InnerB : A.InnerA()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
B().InnerB()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
open class A(val s: String) {
|
||||
open inner class B(val s: String) {
|
||||
fun testB() = s + this@A.s
|
||||
}
|
||||
|
||||
open inner class C(): A("C") {
|
||||
fun testC() =
|
||||
B("B_").testB()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = A("A").C().testC()
|
||||
return if (res == "B_C") "OK" else res;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
open class A(val s: String) {
|
||||
|
||||
val z = s
|
||||
|
||||
fun test() = s
|
||||
|
||||
open inner class B(s: String): A(s) {
|
||||
fun testB() = z + test()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = A("Fail").B("OK").testB()
|
||||
return if (res == "OKOK") "OK" else res;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
class Outer(val foo: StringBuilder) {
|
||||
inner class Inner() {
|
||||
fun len() : Int {
|
||||
return foo.length
|
||||
}
|
||||
}
|
||||
|
||||
fun test() : Inner {
|
||||
return Inner()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val sb = StringBuilder("xyzzy")
|
||||
val o = Outer(sb)
|
||||
val i = o.test()
|
||||
val l = i.len()
|
||||
return if (l != 5) "fail" else "OK"
|
||||
}
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FILE: CompanionInitialization.java
|
||||
|
||||
public class CompanionInitialization {
|
||||
|
||||
public static Object getCompanion() {
|
||||
return IStatic.Companion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: CompanionInitialization.kt
|
||||
|
||||
open class Static(): IStatic {
|
||||
val p = IStatic::class.java.getDeclaredField("const").get(null)
|
||||
}
|
||||
|
||||
interface IStatic {
|
||||
fun doSth() {
|
||||
}
|
||||
|
||||
companion object : Static() {
|
||||
const val const = 1;
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
IStatic.doSth()
|
||||
|
||||
val companion: Any? = CompanionInitialization.getCompanion()
|
||||
if (companion == null) return "fail 1"
|
||||
if (companion != IStatic) return "fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
public class StockMarketTableModel() {
|
||||
|
||||
public fun getColumnCount() : Int {
|
||||
return COLUMN_TITLES?.size!!
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val COLUMN_TITLES : Array<Int?> = arrayOfNulls<Int>(10)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String = if(StockMarketTableModel().getColumnCount()==10) "OK" else "fail"
|
||||
@@ -0,0 +1,19 @@
|
||||
// Won't ever work with JS backend.
|
||||
// TODO: Consider rewriting this test without using threads, since the issue is not about threads at all.
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
object RefreshQueue {
|
||||
val any = Any()
|
||||
val workerThread: Thread = Thread(object : Runnable {
|
||||
override fun run() {
|
||||
val a = any
|
||||
val b = RefreshQueue.any
|
||||
if (a != b) throw AssertionError()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
RefreshQueue.workerThread.run()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// TODO: Enable when JS backend supports Java class library
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
public class SomeClass() : java.lang.Object() {
|
||||
}
|
||||
|
||||
public fun box():String {
|
||||
System.out?.println(SomeClass().getClass())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
public object SomeClass {
|
||||
private val work = object : Runnable {
|
||||
override fun run() {
|
||||
foo()
|
||||
}
|
||||
}
|
||||
|
||||
private fun foo(): Unit {
|
||||
}
|
||||
|
||||
public fun run(): Unit = work.run()
|
||||
}
|
||||
|
||||
interface Runnable {
|
||||
fun run(): Unit
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
SomeClass.run()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun f(a : Int?, b : Int.(Int)->Int) = a?.b(1)
|
||||
|
||||
fun box(): String {
|
||||
val x = f(1) { this+it+2 }
|
||||
return if (x == 4) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
interface Creator<T> {
|
||||
fun create() : T
|
||||
}
|
||||
|
||||
class Actor(val code: String = "OK")
|
||||
|
||||
interface Factory : Creator<Actor>
|
||||
|
||||
class MyFactory() : Factory {
|
||||
override fun create(): Actor = Actor()
|
||||
}
|
||||
|
||||
fun box() : String = MyFactory().create().code
|
||||
@@ -0,0 +1,17 @@
|
||||
class MyClass(var fnc : () -> String) {
|
||||
|
||||
fun test(): String {
|
||||
return fnc()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun printtest() : String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var c = MyClass({ printtest() })
|
||||
|
||||
return c.test()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// TODO: Enable when JS backend supports Java class library, since FunctionX are required for interoperation
|
||||
// IGNORE_BACKEND: JS
|
||||
class Works() : Function0<Any> {
|
||||
public override fun invoke():Any {
|
||||
return "Works" as Any
|
||||
}
|
||||
}
|
||||
class Broken() : Function0<String> {
|
||||
public override fun invoke():String {
|
||||
return "Broken"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val works1: ()->Any = Works();
|
||||
works1()
|
||||
|
||||
val broken1: ()->String = Broken();
|
||||
broken1()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
data class Pair<First, Second>(val first: First, val second: Second)
|
||||
|
||||
fun parseCatalogs(hashMap: Any?) {
|
||||
val r = toHasMap(hashMap)
|
||||
if (!r.first) {
|
||||
return
|
||||
}
|
||||
val nodes = r.second
|
||||
}
|
||||
|
||||
fun toHasMap(value: Any?): Pair<Boolean, HashMap<String, Any?>?> {
|
||||
if(value is HashMap<*, *>) {
|
||||
return Pair(true, value as HashMap<String, Any?>)
|
||||
}
|
||||
return Pair(false, null as HashMap<String, Any?>?)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
parseCatalogs(null)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box() : String {
|
||||
var i = 0
|
||||
{
|
||||
i++
|
||||
}()
|
||||
i++ //the problem is here
|
||||
// i = i + 1 //this way it works
|
||||
return if (i == 2) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun box(): String {
|
||||
return Foo().doBar("OK")
|
||||
}
|
||||
|
||||
class Foo() {
|
||||
val bar : (str : String) -> String = { it }
|
||||
|
||||
fun doBar(str : String): String {
|
||||
return bar(str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class T(val f : () -> Any?) {
|
||||
fun call() : Any? = f()
|
||||
}
|
||||
fun box(): String {
|
||||
return T({ "OK" }).call() as String
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class Foo(
|
||||
var state : Int,
|
||||
val f : (Int) -> Int){
|
||||
|
||||
fun next() : Int {
|
||||
val nextState = f(state)
|
||||
state = nextState
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = Foo(23, {x -> 2 * x})
|
||||
return if (f.next() == 46) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class Greeter(var name : String) {
|
||||
fun greet() {
|
||||
name = name.plus("")
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
Greeter("OK").greet()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class MyList<T>() {
|
||||
var value: T? = null
|
||||
|
||||
operator fun get(index: Int): T = value!!
|
||||
|
||||
operator fun set(index: Int, value: T) { this.value = value }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val list = MyList<Int>()
|
||||
list[17] = 1
|
||||
list[17] = list[18]++
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class Bar {
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
fun xyzzy(x: Any?): String
|
||||
}
|
||||
|
||||
fun buildFoo(bar: Bar.() -> Unit): Foo {
|
||||
return object : Foo {
|
||||
override fun xyzzy(x: Any?): String {
|
||||
(x as? Bar)?.bar()
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val foo = buildFoo({})
|
||||
return foo.xyzzy(Bar())
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
public val f : ()->String = {"OK"}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
return a.f() // does not work: (in runtime) ClassCastException: A cannot be cast to kotlin.Function0
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
public inline fun Int.times(body : () -> Unit) {
|
||||
var count = this;
|
||||
while (count > 0) {
|
||||
body()
|
||||
count--
|
||||
}
|
||||
}
|
||||
|
||||
fun calc() : Int {
|
||||
val a = ArrayList<()->Int>()
|
||||
2.times {
|
||||
var j = 1
|
||||
a.add({ j })
|
||||
++j
|
||||
}
|
||||
var sum = 0
|
||||
for (f in a) {
|
||||
val g = f as () -> Int
|
||||
sum += g()
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val x = calc()
|
||||
return if (x == 4) "OK" else x.toString()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
interface A {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
class B1 : A {
|
||||
override fun foo() = 10
|
||||
}
|
||||
|
||||
class B2(val z: Int) : A {
|
||||
override fun foo() = z
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun f1(b: B1): Int {
|
||||
val o = object : A by b { }
|
||||
return o.foo()
|
||||
}
|
||||
|
||||
fun f2(b: B2): Int {
|
||||
val o = object : A by B2(b.z) { }
|
||||
return o.foo()
|
||||
}
|
||||
|
||||
fun f3(b: B2, mult: Int): Int {
|
||||
val o = object : A by B2(mult * b.z) { }
|
||||
return o.foo()
|
||||
}
|
||||
|
||||
fun f4(b: B1, x: Int, y: Int, z: Int): Int {
|
||||
val o = object : A by b {
|
||||
fun bar() = x + y + z
|
||||
}
|
||||
return o.foo()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (f1(B1()) != 10) return "fail #1"
|
||||
if (f2(B2(239)) != 239) return "fail #2"
|
||||
if (f3(B2(239), 2) != 239*2) return "fail #3"
|
||||
if (f4(B1(), 1, 2, 3) != 10) return "fail #4"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// TODO: Enable when JS backend supports Java class library
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
public open class Test(): java.util.RandomAccess, Cloneable, java.io.Serializable
|
||||
{
|
||||
public override fun clone(): Test = Test() // Override 'clone()' with more precise type 'Test'
|
||||
|
||||
public override fun toString() = "OK"
|
||||
}
|
||||
|
||||
fun box() = Test().clone().toString()
|
||||
@@ -0,0 +1,15 @@
|
||||
class A {
|
||||
companion object {
|
||||
val b = 0
|
||||
val c = b
|
||||
|
||||
init {
|
||||
val d = b
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A()
|
||||
return if (A.c == A.b) "OK" else "Fail"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
class JsonObject() {
|
||||
}
|
||||
|
||||
class JsonArray() {
|
||||
}
|
||||
|
||||
public interface Formatter<in IN: Any, out OUT: Any> {
|
||||
public fun format(source: IN?): OUT
|
||||
}
|
||||
|
||||
public interface MultiFormatter <in IN: Any, out OUT: Any> {
|
||||
public fun format(source: Collection<IN>): OUT
|
||||
}
|
||||
|
||||
public class Project() {
|
||||
}
|
||||
|
||||
public interface JsonFormatter<in IN: Any>: Formatter<IN, JsonObject>, MultiFormatter<IN, JsonArray> {
|
||||
public override fun format(source: Collection<IN>): JsonArray {
|
||||
return JsonArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class ProjectJsonFormatter(): JsonFormatter<Project> {
|
||||
public override fun format(source: Project?): JsonObject {
|
||||
return JsonObject()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val formatter = ProjectJsonFormatter()
|
||||
return if (formatter.format(Project()) != null) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
public interface LoggerAware {
|
||||
public val logger: StringBuilder
|
||||
}
|
||||
|
||||
public abstract class HttpServer(): LoggerAware {
|
||||
public fun start() {
|
||||
logger.append("OK")
|
||||
}
|
||||
}
|
||||
|
||||
public class MyHttpServer(): HttpServer() {
|
||||
public override val logger = StringBuilder()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val server = MyHttpServer()
|
||||
server.start()
|
||||
return server.logger.toString()!!
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
import java.util.AbstractList
|
||||
|
||||
class MyList(): AbstractList<String>() {
|
||||
public fun getModificationCount(): Int = modCount
|
||||
public override fun get(index: Int): String = ""
|
||||
public override val size: Int get() = 0
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (MyList().getModificationCount() == 0) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
fun box() : String{
|
||||
val set = HashSet<String>()
|
||||
set.add("foo")
|
||||
val t1 = "foo" in set // returns true, valid
|
||||
if(!t1) return "fail1"
|
||||
val t2 = "foo" !in set // returns true, invalid
|
||||
if(t2) return "fail2"
|
||||
val t3 = "bar" in set // returns false, valid
|
||||
if(t3) return "fail3"
|
||||
val t4 = "bar" !in set // return false, invalid
|
||||
if(!t4) return "fail4"
|
||||
val t5 = when("foo") {
|
||||
in set -> true
|
||||
else -> false
|
||||
}
|
||||
if(!t5) return "fail5"
|
||||
val t6 = when("foo") {
|
||||
!in set -> true
|
||||
else -> false
|
||||
}
|
||||
if(t6) return "fail6"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package test
|
||||
|
||||
interface A {
|
||||
public val c: String
|
||||
get() = "OK"
|
||||
}
|
||||
|
||||
interface B {
|
||||
private val c: String
|
||||
get() = "FAIL"
|
||||
}
|
||||
|
||||
open class C {
|
||||
private val c: String = "FAIL"
|
||||
}
|
||||
|
||||
open class D: C(), A, B {
|
||||
val b = c
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return D().c
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fun box() = Class().printSome()
|
||||
|
||||
public abstract class AbstractClass<T> {
|
||||
public fun printSome() : T = some
|
||||
|
||||
public abstract val some: T
|
||||
}
|
||||
|
||||
public class Class: AbstractClass<String>() {
|
||||
public override val some: String
|
||||
get() = "OK"
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public fun box() : String {
|
||||
if ( 0 == 0 ) { // Does not crash if either this...
|
||||
if ( 0 == 0 ) { // ...or this is changed to if ( true )
|
||||
// Does not crash if the following is uncommented.
|
||||
//println("foo")
|
||||
}
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun f1(a : Any?) {}
|
||||
fun f2(a : Boolean?) {}
|
||||
fun f3(a : Any) {}
|
||||
fun f4(a : Boolean) {}
|
||||
|
||||
fun box() : String {
|
||||
f1(1 == 1)
|
||||
f2(1 == 1)
|
||||
f3(1 == 1)
|
||||
f4(1 == 1)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package x
|
||||
|
||||
class Outer() {
|
||||
companion object {
|
||||
class Inner() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box (): String {
|
||||
val inner = Outer.Companion.Inner()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
interface B {
|
||||
val c: Int
|
||||
get() = 2
|
||||
}
|
||||
|
||||
class A(val b: B) : B by b {
|
||||
override val c: Int = 3
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = A(object: B {}).c
|
||||
return if (c == 3) "OK" else "fail: $c"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
open class A {
|
||||
open fun foo() = "OK"
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
override fun foo() = super.foo()
|
||||
}
|
||||
|
||||
interface I
|
||||
|
||||
class C : I, B() {
|
||||
override fun foo() = super<B>.foo()
|
||||
}
|
||||
|
||||
fun box() = C().foo()
|
||||
@@ -0,0 +1,17 @@
|
||||
open class A {
|
||||
open val foo: String = "OK"
|
||||
}
|
||||
|
||||
open class B : A() {
|
||||
inner class E {
|
||||
val foo: String = super<A>@B.foo
|
||||
}
|
||||
}
|
||||
|
||||
class C : B() {
|
||||
inner class D {
|
||||
val foo: String = super<B>@C.foo
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = C().foo
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box() : String {
|
||||
val o = object {
|
||||
|
||||
inner class C {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
}
|
||||
return o.C().foo()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package example2
|
||||
|
||||
fun box() = Context.OsType.OK.toString()
|
||||
|
||||
object Context
|
||||
{
|
||||
public enum class OsType {
|
||||
WIN2000, WINDOWS, MACOSX, LINUX, OTHER, OK;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class IntRange {
|
||||
operator fun contains(a: Int) = (1..2).contains(a)
|
||||
}
|
||||
|
||||
class C() {
|
||||
operator fun rangeTo(i: Int) = IntRange()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (2 in C()..2) {
|
||||
2 == 2
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
open class Factory(p: Int)
|
||||
|
||||
class A {
|
||||
companion object : Factory(1)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
A
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
interface Trait {
|
||||
fun foo() = "O"
|
||||
fun bar(): String
|
||||
}
|
||||
|
||||
class SimpleClass : Trait {
|
||||
override fun bar() = "K"
|
||||
}
|
||||
|
||||
// Delegating 'toString' doesn't work, see KT-9519
|
||||
class ComplexClass : Trait by SimpleClass() {
|
||||
fun qux() = foo() + bar()
|
||||
}
|
||||
|
||||
fun box() = ComplexClass().qux()
|
||||
@@ -0,0 +1,11 @@
|
||||
interface A {
|
||||
val result: String
|
||||
}
|
||||
|
||||
class Base(override val result: String) : A
|
||||
|
||||
open class Derived : A by Base("OK")
|
||||
|
||||
class Z : Derived()
|
||||
|
||||
fun box() = Z().result
|
||||
@@ -0,0 +1,13 @@
|
||||
class KeySpan(val left: String) {
|
||||
|
||||
public fun matches(value : String) : Boolean {
|
||||
|
||||
return left > value && left > value
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
KeySpan("1").matches("3")
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
interface A {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
interface B {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
class Z(val a: A) : A by a, B
|
||||
|
||||
fun box(): String {
|
||||
val s = Z(object : A {
|
||||
override fun foo(): Int {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
return if (s.foo() == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
fun launch(f : () -> Unit) {
|
||||
f()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val list = ArrayList<Int>()
|
||||
val foo : () -> Unit = {
|
||||
list.add(2) //first exception
|
||||
}
|
||||
foo()
|
||||
|
||||
launch({
|
||||
list.add(3)
|
||||
})
|
||||
|
||||
val bar = {
|
||||
val x = 1 //second exception
|
||||
}
|
||||
bar()
|
||||
|
||||
return if (list.size == 2 && list.get(0) == 2 && list.get(1) == 3) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
interface A {
|
||||
fun test(): String
|
||||
}
|
||||
|
||||
interface B {
|
||||
fun test(): String
|
||||
}
|
||||
|
||||
interface C: A, B
|
||||
|
||||
class Z(val param: String): C {
|
||||
|
||||
override fun test(): String {
|
||||
return param
|
||||
}
|
||||
}
|
||||
|
||||
public class MyClass(val value : C) : C by value {
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = MyClass(Z("OK"))
|
||||
return s.test()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
var s1 = (l1@ "s")
|
||||
val s2 = (l2@ if (l3@ true) s1 else null)
|
||||
return if (s2 == "s") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
class MyNumber(val i: Int) {
|
||||
operator fun inc(): MyNumber = MyNumber(i+1)
|
||||
}
|
||||
|
||||
class MNR(var ref: MyNumber) {}
|
||||
|
||||
fun test1() : Boolean {
|
||||
var m = MyNumber(42)
|
||||
|
||||
m++
|
||||
if (m.i != 43) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun test2() : Boolean {
|
||||
var m = MyNumber(44)
|
||||
|
||||
var m2 = m++
|
||||
if (m2.i != 44) return false
|
||||
if (m.i != 45) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun test3() : Boolean {
|
||||
var mnr = MNR(MyNumber(42))
|
||||
mnr.ref++
|
||||
if (mnr.ref.i != 43) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun test4() : Boolean {
|
||||
var mnr = MNR(MyNumber(42))
|
||||
val m3 = mnr.ref++
|
||||
if (m3.i != 42) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun test5() : Boolean {
|
||||
var mnr = Array<MyNumber>(2,{MyNumber(42)})
|
||||
mnr[0]++
|
||||
if (mnr[0].i != 43) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun test6() : Boolean {
|
||||
var mnr = Array<MyNumber>(2,{it -> MyNumber(42-it)})
|
||||
mnr[1] = mnr[0]++
|
||||
if (mnr[0].i != 43) return false
|
||||
if (mnr[1].i != 42) return false
|
||||
return true
|
||||
}
|
||||
|
||||
class MyArrayList<T>() {
|
||||
private var value17: T? = null
|
||||
private var value39: T? = null
|
||||
operator fun get(index: Int): T {
|
||||
if (index == 17) return value17!!
|
||||
if (index == 39) return value39!!
|
||||
throw Exception()
|
||||
}
|
||||
operator fun set(index: Int, value: T): T? {
|
||||
if (index == 17) value17 = value
|
||||
else if (index == 39) value39 = value
|
||||
else throw Exception()
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
fun test7() : Boolean {
|
||||
var mnr = MyArrayList<MyNumber>()
|
||||
mnr[17] = MyNumber(42)
|
||||
mnr[17]++
|
||||
if (mnr[17].i != 43) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun test8() : Boolean {
|
||||
var mnr = MyArrayList<MyNumber>()
|
||||
mnr[17] = MyNumber(42)
|
||||
mnr[39] = mnr[17]++
|
||||
if (mnr[17].i != 43) return false
|
||||
if (mnr[39].i != 42) return false
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
fun box() : String {
|
||||
var m = MyNumber(42)
|
||||
|
||||
if (!test1()) return "fail test 1"
|
||||
if (!test2()) return "fail test 2"
|
||||
if (!test3()) return "fail test 3"
|
||||
if (!test4()) return "fail test 4"
|
||||
|
||||
if (!test5()) return "fail test 5"
|
||||
if (!test6()) return "fail test 6"
|
||||
if (!test7()) return "fail test 7"
|
||||
if (!test8()) return "fail test 8"
|
||||
|
||||
|
||||
++m
|
||||
if (m.i != 43) return "fail 0"
|
||||
|
||||
var m1 = ++m
|
||||
if (m1.i != 44) return "fail 3"
|
||||
if (m.i != 44) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
class A() {
|
||||
var xi = 0
|
||||
var xin : Int? = 0
|
||||
var xinn : Int? = null
|
||||
|
||||
var xl = 0.toLong()
|
||||
var xln : Long? = 0.toLong()
|
||||
var xlnn : Long? = null
|
||||
|
||||
var xb = 0.toByte()
|
||||
var xbn : Byte? = 0.toByte()
|
||||
var xbnn : Byte? = null
|
||||
|
||||
var xf = 0.toFloat()
|
||||
var xfn : Float? = 0.toFloat()
|
||||
var xfnn : Float? = null
|
||||
|
||||
var xd = 0.toDouble()
|
||||
var xdn : Double? = 0.toDouble()
|
||||
var xdnn : Double? = null
|
||||
|
||||
var xs = 0.toShort()
|
||||
var xsn : Short? = 0.toShort()
|
||||
var xsnn : Short? = null
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
fun test1() : Boolean {
|
||||
try {
|
||||
return true
|
||||
} finally {
|
||||
if(true) // otherwise we wisely have unreachable code
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var x = true
|
||||
fun test2() : Boolean {
|
||||
try {
|
||||
} finally {
|
||||
x = false;
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
fun test3() : Int {
|
||||
var y = 0
|
||||
try {
|
||||
++y
|
||||
} finally {
|
||||
++y
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
var z = 0
|
||||
fun test4() : Int {
|
||||
z = 0
|
||||
return try {
|
||||
try {
|
||||
z++
|
||||
}
|
||||
finally {
|
||||
z++
|
||||
}
|
||||
} finally {
|
||||
++z
|
||||
}
|
||||
}
|
||||
|
||||
fun test5() : Int {
|
||||
var x = 0
|
||||
while(true) {
|
||||
try {
|
||||
if(x < 10)
|
||||
x++
|
||||
else
|
||||
break
|
||||
}
|
||||
finally {
|
||||
x++
|
||||
}
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
fun test6() : Int {
|
||||
var x = 0
|
||||
while(x < 10) {
|
||||
try {
|
||||
x++
|
||||
continue
|
||||
}
|
||||
finally {
|
||||
x++
|
||||
}
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(test1()) return "test1 failed"
|
||||
if(test2()) return "test2 failed"
|
||||
if(test3() != 2) return "test3 failed"
|
||||
if(test4() != 0) return "test4 failed"
|
||||
if(test5() != 11) return "test5 failed"
|
||||
if(test6() != 10) return "test6 failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
var GUEST_USER_ID = 3
|
||||
val USER_ID =
|
||||
try {
|
||||
getUserIdFromEnvironment()
|
||||
}
|
||||
catch (e : UnsupportedOperationException) {
|
||||
++GUEST_USER_ID
|
||||
}
|
||||
|
||||
val USER_ID_2 =
|
||||
try {
|
||||
getUserIdFromEnvironment()
|
||||
}
|
||||
catch (e : UnsupportedOperationException) {
|
||||
GUEST_USER_ID
|
||||
}
|
||||
finally {
|
||||
GUEST_USER_ID++
|
||||
}
|
||||
|
||||
fun getUserIdFromEnvironment() : Int = throw UnsupportedOperationException()
|
||||
|
||||
fun box() : String {
|
||||
if(USER_ID != 4) return "test0 failed"
|
||||
if(USER_ID_2 != 4) return "test2 failed"
|
||||
if(GUEST_USER_ID != 5) return "test3 failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
class Reluctant() {
|
||||
init {
|
||||
throw Exception("I'm not coming out")
|
||||
}
|
||||
}
|
||||
|
||||
fun test1() : String {
|
||||
try {
|
||||
val b = Reluctant()
|
||||
return "Surprise!"
|
||||
}
|
||||
catch (ex : Exception) {
|
||||
return "I told you so"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box() : String {
|
||||
if(test1() != "I told you so") return "test1 failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package mult_constructors_3_bug
|
||||
|
||||
public open class Identifier() {
|
||||
private var myNullable : Boolean = true
|
||||
companion object {
|
||||
open public fun init(isNullable : Boolean) : Identifier {
|
||||
val id = Identifier()
|
||||
id.myNullable = isNullable
|
||||
return id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
Identifier.init(true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// TODO: Enable for JS when it supports Java class library.
|
||||
// IGNORE_BACKEND: JS
|
||||
// fails on JS with TypeError: imported$plus is not a function, it is undefined.
|
||||
|
||||
operator fun <K, V> MutableMap<K, V>.set(key : K, value : V) = put(key, value)
|
||||
|
||||
fun box() : String {
|
||||
|
||||
val commands : MutableMap<String, String> = HashMap()
|
||||
|
||||
commands["c1"] = "239"
|
||||
if(commands["c1"] != "239") return "fail"
|
||||
|
||||
commands["c1"] += "932"
|
||||
return if(commands["c1"] == "239932") "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
fun test1(str: String): String {
|
||||
data class A(val x: Int) {
|
||||
fun foo() = str
|
||||
}
|
||||
return A(0).copy().foo()
|
||||
}
|
||||
|
||||
class TestClass(val x: String) {
|
||||
fun foo(): String {
|
||||
data class A(val x: Int) {
|
||||
fun foo() = this@TestClass.x
|
||||
}
|
||||
return A(0).copy().foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(str: String): String = TestClass(str).foo()
|
||||
|
||||
fun test3(str: String): String {
|
||||
var xx = ""
|
||||
data class A(val x: Int) {
|
||||
fun foo(): String { xx = str; return xx }
|
||||
}
|
||||
return A(0).copy().foo()
|
||||
}
|
||||
|
||||
fun test4(str: String): String {
|
||||
var xx = ""
|
||||
fun bar(s: String): String { xx = s; return xx }
|
||||
data class A(val x: Int) {
|
||||
fun foo(): String = bar(str)
|
||||
}
|
||||
return A(0).copy().foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return when {
|
||||
test1("test1") != "test1" -> "Failed #1 (parameter capture)"
|
||||
test2("test2") != "test2" -> "Failed #2 ('this' capture)"
|
||||
test3("test3") != "test3" -> "Failed #3 ('var' capture)"
|
||||
test4("test4") != "test4" -> "Failed #4 (local function capture)"
|
||||
else -> "OK"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
interface Id<T> {
|
||||
val id: T
|
||||
}
|
||||
|
||||
data class Actor (
|
||||
override val id: Int,
|
||||
val firstName: String,
|
||||
val lastName: String
|
||||
) : Id<Int>
|
||||
|
||||
fun box(): String {
|
||||
val a1 = Actor(1, "Jeff", "Bridges")
|
||||
|
||||
val a1c = a1.copy()
|
||||
if (a1c.id != a1.id) return "Failed: a1.copy().id==${a1c.id}"
|
||||
|
||||
val a2 = Actor(2, "Jeff", "Bridges")
|
||||
if (a2 == a1) return "Failed: a2==a1"
|
||||
|
||||
// Assume that our hashCode is good enough for this test :)
|
||||
if (a2.hashCode() == a1.hashCode()) return "Failed: a2.hashCode()==a1.hashCode()"
|
||||
|
||||
a1.toString()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
class mInt(val i : Int) {
|
||||
override fun toString() : String = "mint: $i"
|
||||
operator fun plus(i : Int) = mInt(this.i + i)
|
||||
operator fun inc() = mInt(i + 1)
|
||||
}
|
||||
|
||||
class MyArray() {
|
||||
val a = Array<mInt>(10, {mInt(0)})
|
||||
operator fun get(i : mInt) : mInt = a[i.i]
|
||||
operator fun set(i : mInt, v : mInt) {
|
||||
a[i.i] = v
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a = MyArray()
|
||||
var i = mInt(0)
|
||||
a[i++]
|
||||
a[i++] = mInt(1)
|
||||
for (i in 0..9)
|
||||
a[mInt(i)]
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
public class CalculatorConstants(
|
||||
val id: Long = 0,
|
||||
val detour: Double = 0.0,
|
||||
val taxi: Double = 0.0,
|
||||
val loop: Double = 0.0,
|
||||
val planeCondition: Double = 0.0,
|
||||
val co2PerKerosene: Double = 0.0,
|
||||
val freight: Double = 0.0,
|
||||
val rfi: Double = 0.0,
|
||||
val rfiAltitude: Double = 0.0,
|
||||
val averageContribution: Double = 0.0,
|
||||
val singleContribution: Double = 0.0,
|
||||
val returnContribution: Double = 0.0,
|
||||
val defraFactor: Double = 0.0,
|
||||
val airCondMult: Double = 0.0,
|
||||
val autoTransMult: Double = 0.0,
|
||||
val hybridDefault: String? = null,
|
||||
val travelClassOne: Double = 0.0,
|
||||
val status: String = "OK"
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val c = CalculatorConstants()
|
||||
return c.status
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// TODO: Enable for JS when it supports Java class library.
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
class List<T>(val head: T, val tail: List<T>? = null)
|
||||
|
||||
fun <T> List<T>.mapHead(f: (T)-> T): List<T> = List<T>(f(head), null)
|
||||
|
||||
fun box() : String {
|
||||
val a: Int = List<Int>(1).mapHead{it * 2}.head
|
||||
System.out?.println(a)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
operator fun Int?.inc() : Int { if (this != null) return this.inc() else throw NullPointerException() }
|
||||
|
||||
public fun box() : String {
|
||||
var i : Int? = 10
|
||||
val j = i++
|
||||
|
||||
return if(j==10 && 11 == i) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
operator fun Int?.inc() = this!!.inc()
|
||||
|
||||
public fun box() : String {
|
||||
var i : Int? = 10
|
||||
val j = i++
|
||||
|
||||
return if(j==10 && 11 == i) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testFun1(str: String): String {
|
||||
val local = str
|
||||
|
||||
class Local {
|
||||
fun foo() = str
|
||||
}
|
||||
|
||||
val list = listOf(0).map { Local() }
|
||||
return list[0].foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return when {
|
||||
testFun1("test1") != "test1" -> "Fail #1"
|
||||
else -> "OK"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
fun testFun1(str: String): String {
|
||||
val capture = str
|
||||
|
||||
class A {
|
||||
val x = capture
|
||||
}
|
||||
|
||||
return A().x
|
||||
}
|
||||
|
||||
|
||||
fun testFun2(str: String): String {
|
||||
class A {
|
||||
val x = str
|
||||
}
|
||||
fun bar() = A()
|
||||
return bar().x
|
||||
}
|
||||
|
||||
|
||||
class TestClass(val str: String) {
|
||||
var xx: String? = null
|
||||
|
||||
init {
|
||||
class A {
|
||||
val x = str
|
||||
}
|
||||
|
||||
xx = A().x
|
||||
}
|
||||
}
|
||||
|
||||
fun testFun3(str: String): String = TestClass(str).xx!!
|
||||
|
||||
|
||||
fun String.testFun4(): String {
|
||||
class A {
|
||||
val x = this@testFun4
|
||||
}
|
||||
return A().x
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return when {
|
||||
testFun1("test1") != "test1" -> "Fail #1 (local class with capture)"
|
||||
testFun2("test2") != "test2" -> "Fail #2 (local class with capture ctor in another context)"
|
||||
testFun3("test3") != "test3" -> "Fail #3 (local class with capture ctor in init{ ... })"
|
||||
"test4".testFun4() != "test4" -> "Fail #4 (local class with extension receiver)"
|
||||
else -> "OK"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
operator fun Int.plus(a: Int?) = this + a!!
|
||||
|
||||
public open class PerfectNumberFinder() {
|
||||
open public fun isPerfect(number : Int) : Boolean {
|
||||
var factors : MutableList<Int?> = ArrayList<Int?>()
|
||||
factors?.add(1)
|
||||
factors?.add(number)
|
||||
for (i in 2..(Math.sqrt((number).toDouble()) - 1).toInt())
|
||||
if (((number % i) == 0)) {
|
||||
factors?.add(i)
|
||||
if (((number / i) != i))
|
||||
factors?.add((number / i))
|
||||
|
||||
}
|
||||
|
||||
var sum : Int = 0
|
||||
for (i : Int? in factors)
|
||||
sum += i
|
||||
return ((sum - number) == number)
|
||||
}
|
||||
}
|
||||
|
||||
fun box () = if (PerfectNumberFinder().isPerfect(28)) "OK" else "fail"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user