JS: create new common directory for all generated tests, migrate several tests there
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package foo
|
||||
|
||||
annotation class bar
|
||||
|
||||
public annotation class Baz(val a: String)
|
||||
|
||||
fun box(): String {
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
abstract class A {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String = (A::foo)(B())
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
val s = "sA"
|
||||
fun memBar(other: String): String = s +":memBar:" + other
|
||||
}
|
||||
|
||||
fun A.extBar(other: String):String = s + ":extBar:" + other
|
||||
|
||||
fun box():String {
|
||||
fun A.locExtBar(other: String):String = s + ":locExtBar:" + other
|
||||
|
||||
val a = A()
|
||||
|
||||
var r = (A::memBar)(a, "!!")
|
||||
if (r != "sA:memBar:!!") return r
|
||||
|
||||
r = (A::extBar)(a, "!!")
|
||||
if (r != "sA:extBar:!!") return r
|
||||
|
||||
r = (A::locExtBar)(a, "!!")
|
||||
if (r != "sA:locExtBar:!!") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
package foo
|
||||
|
||||
fun run(a: A, arg: String, funRef:(A, String) -> String): String {
|
||||
return funRef(a, arg)
|
||||
}
|
||||
|
||||
class A {
|
||||
val s = "sA"
|
||||
fun memBar(other: String): String = s +":memBar:" + other
|
||||
}
|
||||
|
||||
fun A.extBar(other: String):String = s + ":extBar:" + other
|
||||
|
||||
fun box():String {
|
||||
fun A.locExtBar(other: String):String = s + ":locExtBar:" + other
|
||||
|
||||
val a = A()
|
||||
|
||||
var r = run(a, "!!", A::memBar)
|
||||
if (r != "sA:memBar:!!") return r
|
||||
|
||||
r = run(a, "!!", A::extBar)
|
||||
if (r != "sA:extBar:!!") return r
|
||||
|
||||
r = run(a, "!!", A::locExtBar)
|
||||
if (r != "sA:locExtBar:!!") return r
|
||||
|
||||
r = run(a, "!!") { a: A, other: String -> a.s + ":literal:" + other }
|
||||
if (r != "sA:literal:!!") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun bar(k: Int) = k
|
||||
|
||||
fun result() = (A::bar)(this, 111)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().result()
|
||||
if (result != 111) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun o() = 111
|
||||
fun k(k: Int) = k
|
||||
}
|
||||
|
||||
fun A.bar() = (A::o)(this) + (A::k)(this, 222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = x(A())
|
||||
return r
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun foo(result: String):String = result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = x(A(), "OK")
|
||||
|
||||
return r
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
|
||||
fun foo() {
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
x(a)
|
||||
return a.result
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
|
||||
fun foo(newResult: String) {
|
||||
result = newResult
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
x(a, "OK")
|
||||
return a.result
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
open fun foo(a:String,b:String): String = "fooA:" + a + b
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(a:String,b:String): String = "fooB:" + a + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
var ref = A::foo
|
||||
val result = ref(b, "1", "2")
|
||||
return (if (result == "fooB:12") "OK" else result)
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun changeToOK() { result = "OK" }
|
||||
|
||||
val ok = ::changeToOK
|
||||
ok()
|
||||
return result
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
var result = "OK"
|
||||
}
|
||||
|
||||
fun box() = (::A)().result
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A(val result: String)
|
||||
|
||||
fun box() = (::A)("OK").result
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
class A(val x:Int) {
|
||||
var s = "sA"
|
||||
init {
|
||||
s += ":init:" + x
|
||||
}
|
||||
}
|
||||
|
||||
class B(val arg1:String, val arg2:String) {
|
||||
var msg = ""
|
||||
init {
|
||||
msg = arg1 + arg2
|
||||
}
|
||||
}
|
||||
|
||||
fun box():String {
|
||||
val ref = ::A
|
||||
var result = ref(1).s + (::B)("23", "45").msg
|
||||
return (if (result == "sA:init:12345") "OK" else result)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
fun A.foo() = "OK"
|
||||
return (A::foo)(A())
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun result() = (A::bar)(this, "OK")
|
||||
}
|
||||
|
||||
fun A.bar(x: String) = x
|
||||
|
||||
fun box() = A().result()
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo() = (A::bar)(this, "OK")
|
||||
|
||||
fun A.bar(x: String) = x
|
||||
|
||||
fun box() = A().foo()
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: A, arg2: T, funRef:(A, T) -> T): T {
|
||||
return funRef(arg1, arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
var xx: Int = 100
|
||||
}
|
||||
|
||||
fun A.bar(x: Int): Int {
|
||||
this.xx = this.xx * 2
|
||||
return x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val funRef = A::bar
|
||||
val obj = A()
|
||||
var result = funRef(obj, 25)
|
||||
if (result != 25 || obj.xx != 200) return "fail1: result = $result, expected 25; obj.xx = $obj.xx, expected 200"
|
||||
|
||||
result = run(A(), 25, funRef)
|
||||
if (result != 25 || obj.xx != 200) return "fail2: result = $result, expected 25; obj.xx = $obj.xx, expected 200"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> String): String {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = x(A())
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), A::foo)
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> String): String {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo(result: String) = result
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = x(A(), "OK")
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), "OK", A::foo)
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
}
|
||||
|
||||
fun A.foo() {
|
||||
result = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
x(a)
|
||||
|
||||
return a.result
|
||||
}
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> Unit): Unit {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
}
|
||||
|
||||
fun A.foo(newResult: String) {
|
||||
result = newResult
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
x(a, "OK")
|
||||
|
||||
if (a.result != "OK") return a.result
|
||||
|
||||
val a1 = A()
|
||||
run(a1, "OK", A::foo)
|
||||
return a.result
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun Int.is42With(that: Int) = this + 2 * that == 42
|
||||
return if ((Int::is42With)(16, 13)) "OK" else "Fail"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun A.ext() { result = "OK" }
|
||||
|
||||
val f = A::ext
|
||||
f(A())
|
||||
return result
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
fun Int.sum0(other: Int): Int = this + other
|
||||
|
||||
fun box(): String {
|
||||
fun Int.sum1(other: Int): Int = this + other
|
||||
|
||||
val sum2 = fun Int.(other: Int): Int = this + other
|
||||
|
||||
var x = 10
|
||||
x = x.sum0(5)
|
||||
x = x.sum1(5)
|
||||
x = x.sum2(5)
|
||||
|
||||
var y = 10
|
||||
y = (Int::sum0)(y, 5)
|
||||
y = (Int::sum1)(y, 5)
|
||||
y = y.sum2(5)
|
||||
|
||||
var result:String = (if (x == y && x == 25) "OK" else "x=${x} y=${y}")
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo(): String {
|
||||
fun bar() = "OK"
|
||||
val ref = ::bar
|
||||
return ref()
|
||||
}
|
||||
|
||||
val ref = ::foo
|
||||
return ref()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun foo(until: Int): String {
|
||||
fun bar(x: Int): String =
|
||||
if (x == until) "OK" else bar(x + 1)
|
||||
return (::bar)(0)
|
||||
}
|
||||
|
||||
fun box() = foo(10)
|
||||
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo() = "OK"
|
||||
return (::foo)()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val result = "OK"
|
||||
|
||||
fun foo() = result
|
||||
|
||||
return (::foo)()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo(s: String) = s
|
||||
return (::foo)("OK")
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var s = "abc"
|
||||
assertEquals("ABC", (String::toUpperCase)(s))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
|
||||
return funRef(arg1, arg2)
|
||||
}
|
||||
|
||||
fun tmp(o: Int, k: Int) = o + k
|
||||
|
||||
class A {
|
||||
fun bar() = (::tmp)(111, 222)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
var r = run(111, 222, ::tmp)
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
|
||||
return funRef(arg1, arg2)
|
||||
}
|
||||
|
||||
fun tmp(o: Int, k: Int) = o + k
|
||||
|
||||
class A
|
||||
|
||||
fun A.bar() = (::tmp)(111, 222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
var r = run(111, 222, ::tmp)
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(funRef:() -> String): String {
|
||||
return funRef()
|
||||
}
|
||||
|
||||
fun bar() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
val x = ::bar
|
||||
|
||||
var r = x()
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(::bar)
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg: Int, funRef:(Int) -> Int): Int {
|
||||
return funRef(arg)
|
||||
}
|
||||
fun inc(x: Int) = x + 1
|
||||
|
||||
fun box(): String {
|
||||
val funRef = ::inc
|
||||
if (funRef(5) != 6) return "fail1"
|
||||
|
||||
if (run(5, funRef) != 6) return "fail2"
|
||||
|
||||
if (run(5) {x -> x + 1} != 6) return "fail3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
var state = 23
|
||||
|
||||
fun box(): String {
|
||||
fun incrementState(inc: Int) {
|
||||
state += inc
|
||||
}
|
||||
|
||||
val inc = ::incrementState
|
||||
inc(12)
|
||||
inc(-5)
|
||||
inc(27)
|
||||
inc(-15)
|
||||
|
||||
return if (state == 42) "OK" else "Fail $state"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
abstract class Base {
|
||||
val result = "OK"
|
||||
}
|
||||
|
||||
class Derived : Base()
|
||||
|
||||
fun box(): String {
|
||||
return (Base::result).get(Derived())
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object NumberDecrypter {
|
||||
operator fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
|
||||
"four" -> 4
|
||||
"two" -> 2
|
||||
else -> throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
val four: Int by NumberDecrypter
|
||||
|
||||
class A {
|
||||
val two: Int by NumberDecrypter
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = ::four.get()
|
||||
if (x != 4) return "Fail x: $x"
|
||||
val a = A()
|
||||
val y = A::two.get(a)
|
||||
if (y != 2) return "Fail y: $y"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
object Delegate {
|
||||
var value = "lol"
|
||||
|
||||
operator fun getValue(instance: Any?, data: KProperty<*>): String {
|
||||
return value
|
||||
}
|
||||
|
||||
operator fun setValue(instance: Any?, data: KProperty<*>, newValue: String) {
|
||||
value = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var result: String by Delegate
|
||||
|
||||
fun box(): String {
|
||||
val f = ::result
|
||||
if (f.get() != "lol") return "Fail 1: {$f.get()}"
|
||||
Delegate.value = "rofl"
|
||||
if (f.get() != "rofl") return "Fail 2: {$f.get()}"
|
||||
f.set("OK")
|
||||
return f.get()
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package foo
|
||||
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
|
||||
open class A(var msg:String) {
|
||||
}
|
||||
|
||||
class B:A("FromB") {
|
||||
}
|
||||
|
||||
var global:String = ""
|
||||
|
||||
var A.ext:String
|
||||
get() = ":A.ext ${this.msg}:"
|
||||
set(value) { global = ":A.ext ${value}" }
|
||||
|
||||
var B.ext:String
|
||||
get() = ":B.ext ${this.msg}:"
|
||||
set(value) { global = ":B.ext ${value}" }
|
||||
|
||||
fun box(): String {
|
||||
val a = A("Test")
|
||||
|
||||
var refAExt = A::ext
|
||||
var refBExt: KMutableProperty1<B, String> = B::ext
|
||||
|
||||
assertEquals("ext", refAExt.name)
|
||||
assertEquals("ext", refBExt.name)
|
||||
|
||||
assertEquals(":A.ext Test:", refAExt.get(a))
|
||||
assertEquals(":B.ext FromB:", refBExt.get(B()))
|
||||
|
||||
refAExt.set(a, "newA")
|
||||
assertEquals(":A.ext newA", global)
|
||||
|
||||
global = ""
|
||||
refBExt.set(B(), "newB")
|
||||
assertEquals(":B.ext newB", global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
import kotlin.reflect.KProperty1
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
val ref: KProperty1<A, String> = A::foo
|
||||
}
|
||||
|
||||
val foo: String = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return A.ref.get(A())
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
open class A(var msg:String) {
|
||||
open var prop:String = "initA"
|
||||
}
|
||||
|
||||
class B:A("FromB") {
|
||||
override var prop:String = "initB"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var refAProp = A::prop
|
||||
var refBProp = B::prop
|
||||
|
||||
assertEquals("prop", refAProp.name)
|
||||
assertEquals("prop", refBProp.name)
|
||||
|
||||
val a = A("Test")
|
||||
assertEquals("initA", refAProp.get(a))
|
||||
|
||||
refAProp.set(a, "newPropA")
|
||||
assertEquals("newPropA", a.prop)
|
||||
|
||||
val a1 = B()
|
||||
assertEquals("initB", refAProp.get(a1))
|
||||
|
||||
refAProp.set(a1, "newPropB")
|
||||
assertEquals("newPropB", a1.prop)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
open class Base {
|
||||
open val foo = "Base"
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
override val foo = "OK"
|
||||
}
|
||||
|
||||
fun box() = (Base::foo).get(Derived())
|
||||
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
val String.id: String
|
||||
get() = this
|
||||
|
||||
fun box(): String {
|
||||
val pr = String::id
|
||||
|
||||
if (pr.get("123") != "123") return "Fail value: ${pr.get("123")}"
|
||||
|
||||
if (pr.name != "id") return "Fail name: ${pr.name}"
|
||||
|
||||
return pr.get("OK")
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
class A(val x: Int)
|
||||
|
||||
fun box(): String {
|
||||
val p = A::x
|
||||
if (p.get(A(42)) != 42) return "Fail 1"
|
||||
if (p.get(A(-1)) != -1) return "Fail 2"
|
||||
if (p.name != "x") return "Fail 3"
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
var storage = 0
|
||||
|
||||
var Int.foo: Int
|
||||
get() {
|
||||
return this + storage
|
||||
}
|
||||
set(value) {
|
||||
storage = this + value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val pr = Int::foo
|
||||
if (pr.get(42) != 42) return "Fail 1: ${pr.get(42)}"
|
||||
pr.set(200, 39)
|
||||
if (pr.get(-239) != 0) return "Fail 2: ${pr.get(-239)}"
|
||||
if (storage != 239) return "Fail 3: $storage"
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(var value: String)
|
||||
|
||||
fun box(): String {
|
||||
val o = Box("lorem")
|
||||
val prop = Box::value
|
||||
|
||||
if (prop.get(o) != "lorem") return "Fail 1: ${prop.get(o)}"
|
||||
prop.set(o, "ipsum")
|
||||
if (prop.get(o) != "ipsum") return "Fail 2: ${prop.get(o)}"
|
||||
if (o.value != "ipsum") return "Fail 3: ${o.value}"
|
||||
o.value = "dolor"
|
||||
if (prop.get(o) != "dolor") return "Fail 4: ${prop.get(o)}"
|
||||
if ("$o" != "Box(value=dolor)") return "Fail 5: $o"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(val value: String)
|
||||
|
||||
var pr = Box("first")
|
||||
|
||||
fun box(): String {
|
||||
val property = ::pr
|
||||
if (property.get() != Box("first")) return "Fail value: ${property.get()}"
|
||||
if (property.name != "pr") return "Fail name: ${property.name}"
|
||||
property.set(Box("second"))
|
||||
if (property.get().value != "second") return "Fail value 2: ${property.get()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// This test was adapted from compiler/testData/codegen/box/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(val value: String)
|
||||
|
||||
val foo = Box("lol")
|
||||
|
||||
fun box(): String {
|
||||
val property = ::foo
|
||||
if (property.get() != Box("lol")) return "Fail value: ${property.get()}"
|
||||
if (property.name != "foo") return "Fail name: ${property.name}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
var x = 1
|
||||
|
||||
val y = 2
|
||||
|
||||
fun box(): String {
|
||||
var refX = ::x
|
||||
assertEquals(1, refX.get())
|
||||
assertEquals("x", refX.name)
|
||||
|
||||
refX.set(100)
|
||||
assertEquals(100, x)
|
||||
|
||||
var refY = ::y
|
||||
assertEquals(2, refY.get())
|
||||
assertEquals("y", refY.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals('K', 'A' + 10)
|
||||
assertEquals('7', 'A' - 10)
|
||||
|
||||
assertEquals(3, 'd' - 'a')
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(true, 'A' < '\uFFFF')
|
||||
assertEquals(true, 'A' > '\u0000')
|
||||
assertEquals(true, 'A' <= '\u0041')
|
||||
assertEquals(true, 'A' >= '\u0041')
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val chars = mapOf('\u0000' to 0x0000,
|
||||
'\u0001' to 0x0001,
|
||||
'\u0010' to 0x0010,
|
||||
'\u001F' to 0x001F,
|
||||
'\u0064' to 0x0064,
|
||||
'\u00A0' to 0x00A0,
|
||||
'\u00FF' to 0x00FF,
|
||||
'\u0100' to 0x0100,
|
||||
'\uF01F' to 0xF01F)
|
||||
|
||||
for ((char, code) in chars) {
|
||||
assertEquals(code, char.toInt())
|
||||
assertEquals(char, code.toChar())
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals('A', 'A'.toChar(), "toChar")
|
||||
assertEquals(65, 'A'.toInt(), "toInt")
|
||||
assertEquals(65.toShort(), 'A'.toShort(), "toShort")
|
||||
assertEquals(65.toByte(), 'A'.toByte(), "toByte")
|
||||
assertEquals(65.0, 'A'.toDouble(), "toDouble")
|
||||
assertEquals(65.0f, 'A'.toFloat(), "toFloat")
|
||||
assertEquals(65L, 'A'.toLong(), "toLong")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(true, 'A' == 'A')
|
||||
assertEquals(false, 'A'== 'B')
|
||||
assertEquals(false, ('A' as Any) == (65 as Any))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(false, ('A' as Any) is Int)
|
||||
assertEquals(false, ('A' as Any) is Short)
|
||||
assertEquals(false, ('A' as Any) is Byte)
|
||||
assertEquals(false, ('A' as Any) is Float)
|
||||
assertEquals(false, ('A' as Any) is Double)
|
||||
assertEquals(false, ('A' as Any) is Number)
|
||||
|
||||
assertEquals(true, 'A' is Char)
|
||||
assertEquals(true, ('A' as Any) is Char)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(true, 'B' in 'A'..'D')
|
||||
assertEquals(true, 'E' !in 'A'..'D')
|
||||
|
||||
var s = ""
|
||||
for(char in 'A'..'D') {
|
||||
s += char
|
||||
}
|
||||
assertEquals("ABCD", s)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var x: Char = 'A'
|
||||
x++
|
||||
assertEquals('B', x)
|
||||
++x
|
||||
assertEquals('C', x)
|
||||
|
||||
var y = x++
|
||||
assertEquals('C', y)
|
||||
assertEquals('D', x)
|
||||
|
||||
y = ++x
|
||||
assertEquals('E', y)
|
||||
assertEquals('E', x)
|
||||
|
||||
x--
|
||||
assertEquals('D', x)
|
||||
--x
|
||||
assertEquals('C', x)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// KT-4130 object fields are not evaluated correctly
|
||||
|
||||
package foo
|
||||
|
||||
class Foo() {
|
||||
companion object {
|
||||
val bar = "Foo.bar ";
|
||||
var boo = "FAIL";
|
||||
fun baz() = "Foo.baz() "
|
||||
|
||||
fun testImplicitThis(): String {
|
||||
boo = "Implicit"
|
||||
return baz() + bar + boo
|
||||
}
|
||||
fun testExplicitThis(): String {
|
||||
this.boo = "Explicit"
|
||||
return this.baz() + this.bar + this.boo
|
||||
}
|
||||
}
|
||||
|
||||
val a = bar
|
||||
val b = Foo.bar
|
||||
val c = baz()
|
||||
val d = Foo.baz()
|
||||
val e: String
|
||||
val f: String
|
||||
|
||||
init {
|
||||
e = bar
|
||||
f = Foo.bar
|
||||
boo = "O"
|
||||
Foo.boo += "K"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Foo.baz() Foo.bar Implicit", Foo.testImplicitThis(), "testImplicitThis")
|
||||
assertEquals("Foo.baz() Foo.bar Explicit", Foo.testExplicitThis(), "testExplicitThis")
|
||||
|
||||
val foo = Foo()
|
||||
assertEquals("Foo.bar ", foo.a, "foo.a")
|
||||
assertEquals("Foo.bar ", foo.b, "foo.b")
|
||||
assertEquals("Foo.baz() ", foo.c, "foo.c")
|
||||
assertEquals("Foo.baz() ", foo.d, "foo.d")
|
||||
assertEquals("Foo.bar ", foo.e, "foo.e")
|
||||
assertEquals("Foo.bar ", foo.f, "foo.f")
|
||||
|
||||
assertEquals("OK", Foo.boo, "Foo.boo")
|
||||
assertEquals("Foo.bar ", Foo.bar, "Foo.bar")
|
||||
assertEquals("Foo.baz() ", Foo.baz(), "Foo.baz()")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
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,15 @@
|
||||
// See KT-6326, KT-6777
|
||||
package foo
|
||||
|
||||
enum class Foo {
|
||||
A;
|
||||
|
||||
companion object {
|
||||
val a = A
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("A", Foo.a.name)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
interface A {
|
||||
companion object {
|
||||
val OK: String = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return A.OK
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// See KT-11100
|
||||
package foo
|
||||
|
||||
class Div {
|
||||
var className: String? = null
|
||||
|
||||
companion object {
|
||||
operator fun invoke(init: Div.() -> Unit): Div {
|
||||
val div = Div()
|
||||
div.init()
|
||||
return div
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = Div {
|
||||
className = "ui container"
|
||||
}
|
||||
assertEquals("ui container", x.className)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package foo
|
||||
|
||||
interface Named {
|
||||
companion object Bar {
|
||||
val g = "a";
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
companion object {
|
||||
val g = "b";
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("a", Named.Bar.g, "Named.Bar.g")
|
||||
assertEquals("a", Named.g, "Named.g")
|
||||
|
||||
assertEquals("b", Foo.Companion.g, "Foo.Companion.g")
|
||||
assertEquals("b", Foo.g, "Foo.g")
|
||||
|
||||
assertEquals("b", foo(Foo), "foo(Foo)")
|
||||
assertEquals("b", foo(Foo.Companion), "foo(Foo.Companion)")
|
||||
|
||||
assertEquals("c", Named.ext(), "Named.ext()")
|
||||
assertEquals("c", Named.Bar.ext(), "Named.Bar.ext()")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun foo(f: Foo.Companion) = f.g
|
||||
|
||||
fun Named.Bar.ext() = "c"
|
||||
@@ -0,0 +1,25 @@
|
||||
// See KT-6203
|
||||
package foo
|
||||
|
||||
class TestClass {
|
||||
object a {
|
||||
override fun toString() = "a"
|
||||
}
|
||||
|
||||
companion object {
|
||||
object b {
|
||||
override fun toString() = "b"
|
||||
}
|
||||
}
|
||||
|
||||
fun test() = convert(a) + convert(b)
|
||||
}
|
||||
|
||||
fun convert(o: Any) = o.toString()
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("ab", TestClass().test())
|
||||
assertEquals("ab2", convert(TestClass.a) + convert(TestClass.Companion.b) + "2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
var a = 3
|
||||
companion object {
|
||||
var a = -2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
A.a = 2
|
||||
if (A.a != 2) return "A.a != 2, it: ${A.a}"
|
||||
|
||||
val a = A
|
||||
a.a = 3
|
||||
if (a.a != 3) return "a = A; a.a = 3; a != 3, it: ${a.a}"
|
||||
|
||||
if (A().a != 3) return "A().a != 3, it: ${A().a}"
|
||||
|
||||
val x = A()
|
||||
x.a = 4
|
||||
if (x.a != 4) return "x = A(); x.a = 4; x.a != 4, it: ${x.a}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
val a = 3
|
||||
companion object {
|
||||
val a = 2
|
||||
val b = 5
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
if (A.a != 2) return "A.a != 2, it: ${A.a}"
|
||||
if (A.b != 5) return "A.b != 5, it: ${A.b}"
|
||||
|
||||
val b = A
|
||||
if (b.a != 2) return "b = A; b != 2, it: ${b.a}"
|
||||
|
||||
if (A().a != 3) return "A().a != 3, it: ${A().a}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
val a = 3
|
||||
fun foo(): Int {
|
||||
return 5
|
||||
}
|
||||
companion object: A() {
|
||||
val c = a
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object: A() {
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (A.a != 3) return "A.a != 3, it: ${A.a}"
|
||||
if (A.foo() != 5) return "A.foo() != 5, it: ${A.foo()}"
|
||||
|
||||
val a = A
|
||||
if (a.c != 3) return "a = A; a.c != 3, it: ${a.c}"
|
||||
|
||||
if (A().a != 3) return "A().a != 3, it: ${A().a}"
|
||||
|
||||
if (B.a != 3) return "B.a != 3, it: ${B.a}"
|
||||
val b = B
|
||||
if (b.foo() != 5) return "b = B; b.foo() != 5, it: ${b.foo()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package foo
|
||||
|
||||
fun <T> myRun(f: () -> T) = f()
|
||||
@@ -0,0 +1,27 @@
|
||||
package foo
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
fun test(f: () -> String): String {
|
||||
val funLit = { f() }
|
||||
return funLit()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val l = ArrayList<String>()
|
||||
l.add("1 ")
|
||||
l.add("foobar ")
|
||||
l.add("baz")
|
||||
|
||||
val f = {
|
||||
var s = ""
|
||||
for (e in l) s += e
|
||||
s
|
||||
}
|
||||
|
||||
val r = f()
|
||||
if (r != "1 foobar baz") return "$r"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package foo
|
||||
|
||||
fun test(f: () -> String): String {
|
||||
val funLit = { f() }
|
||||
return funLit()
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
return test { "OK" }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
val r = "OK"
|
||||
|
||||
fun simple(s: String? = null): String {
|
||||
if (s != null) return s
|
||||
|
||||
return myRun {
|
||||
simple("OK")
|
||||
}
|
||||
}
|
||||
|
||||
val ok = "OK"
|
||||
fun withClosure(s: String? = null): String {
|
||||
if (s != null) return s
|
||||
|
||||
return ok + myRun {
|
||||
withClosure(ok)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (simple("OK") != "OK") return "failed on simple recursion"
|
||||
|
||||
if (withClosure() != ok + ok) return "failed when closure something"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
class A<T>(val a: T) {
|
||||
val foo = { a }
|
||||
}
|
||||
|
||||
fun <T> T.bar() = { this }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("ok", A("ok").foo())
|
||||
assertEquals("a42", "a42".bar()())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val bar = 12
|
||||
|
||||
val baz = {
|
||||
var result = "test1 "
|
||||
if (true) {
|
||||
val bar = "some text"
|
||||
result += bar
|
||||
}
|
||||
result += bar
|
||||
result
|
||||
}
|
||||
|
||||
val r1 = baz()
|
||||
if (r1 != "test1 some text12") return "r1 = $r1";
|
||||
|
||||
val boo = {
|
||||
var result = "test2 "
|
||||
result += bar
|
||||
if (true) {
|
||||
val bar = 4
|
||||
result += bar
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
val r2 = boo()
|
||||
if (r2 != "test2 124") return "r2 = $r2";
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package foo
|
||||
|
||||
fun funfun(): Boolean {
|
||||
val result = true
|
||||
|
||||
fun foo(): Boolean {
|
||||
fun bar() = result
|
||||
return bar()
|
||||
}
|
||||
|
||||
return foo()
|
||||
}
|
||||
|
||||
fun litlit(): Boolean {
|
||||
val result = true
|
||||
|
||||
return myRun {
|
||||
myRun { result }
|
||||
}
|
||||
}
|
||||
|
||||
fun funlit(): Boolean {
|
||||
val result = true
|
||||
|
||||
fun foo(): Boolean {
|
||||
return myRun { result }
|
||||
}
|
||||
|
||||
return foo()
|
||||
}
|
||||
|
||||
fun litfun(): Boolean {
|
||||
val result = true
|
||||
|
||||
return myRun {
|
||||
fun bar() = result
|
||||
bar()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!funfun()) return "funfun failed"
|
||||
if (!litlit()) return "litlit failed"
|
||||
if (!funlit()) return "funlit failed"
|
||||
if (!litfun()) return "litfun failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
val a = 12
|
||||
var b = 1
|
||||
|
||||
fun boo(c: Int) = c
|
||||
|
||||
fun litlit() {
|
||||
val testName = "litlit"
|
||||
myRun {
|
||||
myRun {
|
||||
assertEquals(12, a, testName)
|
||||
|
||||
assertEquals(1, b, testName)
|
||||
b = 23
|
||||
assertEquals(23, b, testName)
|
||||
|
||||
assertEquals(34, boo(34), testName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun funfun() {
|
||||
val testName = "funfun"
|
||||
fun foo() {
|
||||
fun bar() {
|
||||
assertEquals(12, a, testName)
|
||||
|
||||
assertEquals(1, b, testName)
|
||||
b = 23
|
||||
assertEquals(23, b, testName)
|
||||
|
||||
assertEquals(34, boo(34), testName)
|
||||
}
|
||||
bar()
|
||||
}
|
||||
foo()
|
||||
}
|
||||
|
||||
fun litfun() {
|
||||
val testName = "litfun"
|
||||
myRun {
|
||||
fun bar() {
|
||||
assertEquals(12, a, testName)
|
||||
|
||||
assertEquals(1, b, testName)
|
||||
b = 23
|
||||
assertEquals(23, b, testName)
|
||||
|
||||
assertEquals(34, boo(34), testName)
|
||||
}
|
||||
bar()
|
||||
}
|
||||
}
|
||||
|
||||
fun funlit() {
|
||||
val testName = "funlit"
|
||||
fun foo() {
|
||||
myRun {
|
||||
assertEquals(12, a, testName)
|
||||
|
||||
assertEquals(1, b, testName)
|
||||
b = 23
|
||||
assertEquals(23, b, testName)
|
||||
|
||||
assertEquals(34, boo(34), testName)
|
||||
}
|
||||
}
|
||||
foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A().litlit()
|
||||
A().funfun()
|
||||
A().litfun()
|
||||
A().funlit()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val t = myRun {
|
||||
object {
|
||||
fun boo(param: String): String {
|
||||
return myRun { param }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t.boo("OK")
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// KT-4218 Nested function literal on singleton object fails
|
||||
|
||||
package foo
|
||||
|
||||
object SomeObject {
|
||||
val values = create()
|
||||
fun create() = Array<Array<String>>(1) { y ->
|
||||
Array<String>(1) { x ->
|
||||
"(${x}, ${y})"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (SomeObject.values[0][0] != "(0, 0)") return SomeObject.values[0][0]
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package foo
|
||||
|
||||
object A {
|
||||
val a = 1
|
||||
fun foo() = 31
|
||||
|
||||
val f = { a + foo() }
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object {
|
||||
val a = 21
|
||||
fun foo() = 3
|
||||
|
||||
val f = { this.a + this.foo() }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A.f()
|
||||
if (a != 32) return "a != 32, a = $a"
|
||||
|
||||
val b = B.f()
|
||||
if (b != 24) return "b != 24, b = $b"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// KT-4237 With in with
|
||||
|
||||
package foo
|
||||
|
||||
class A {
|
||||
val ok = "OK"
|
||||
}
|
||||
|
||||
class B
|
||||
|
||||
fun <T> with(o: T, body: T.() -> Unit) {
|
||||
o.body()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var o = ""
|
||||
|
||||
with(A()) {
|
||||
with(B()) {
|
||||
o = ok
|
||||
}
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// KT-4263 Wrong capturing a function literal variable
|
||||
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var foo = { 1 }
|
||||
var bar = 1
|
||||
|
||||
val t = { "${foo()} $bar" }
|
||||
fun b() = "${foo()} $bar"
|
||||
|
||||
foo = { 2 }
|
||||
bar = 2
|
||||
|
||||
assertEquals("2 2", t())
|
||||
assertEquals("2 2", b())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
fun test(): String {
|
||||
fun f(): String = "OK"
|
||||
|
||||
val funLit = { f() }
|
||||
return funLit()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return test()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun simple(s: String? = null): String {
|
||||
if (s != null) return s
|
||||
|
||||
return myRun {
|
||||
simple("OK")
|
||||
}
|
||||
}
|
||||
|
||||
if (simple("OK") != "OK") return "failed on simple recursion"
|
||||
|
||||
val ok = "OK"
|
||||
fun withClosure(s: String? = null): String {
|
||||
if (s != null) return s
|
||||
|
||||
return ok + myRun {
|
||||
withClosure(ok)
|
||||
}
|
||||
}
|
||||
|
||||
if (withClosure() != ok + ok) return "failed when closure something"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
class Foo {
|
||||
val OK = "OK";
|
||||
var result: String = ""
|
||||
init {
|
||||
fun bar(s: String? = null) {
|
||||
if (s != null) {
|
||||
result = s
|
||||
return
|
||||
}
|
||||
|
||||
myRun {
|
||||
bar(OK)
|
||||
}
|
||||
}
|
||||
bar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Foo().result
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var boo = "OK"
|
||||
var foo = object {
|
||||
val bar = object {
|
||||
val baz = boo
|
||||
}
|
||||
}
|
||||
|
||||
return foo.bar.baz
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package foo
|
||||
|
||||
val k = { "K" }
|
||||
|
||||
fun test(): String {
|
||||
val o = { "O" }
|
||||
|
||||
val funLit = { o() + k() }
|
||||
return funLit()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return test()
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package foo
|
||||
|
||||
// workaround for Rhino
|
||||
var n = 0
|
||||
class A {
|
||||
val i = ++n
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
fun A.foo() {
|
||||
fun A.bar() {
|
||||
assertEquals(2, this.i, "check this.i in A.bar()")
|
||||
assertEquals(1, this@foo.i, "check this@foo.i in A.bar()")
|
||||
}
|
||||
val b = { assertEquals(1, this.i, "check this.i in b") }
|
||||
|
||||
assertEquals(1, this.i, "check this.i in A.foo()")
|
||||
A().bar()
|
||||
b()
|
||||
}
|
||||
|
||||
A().foo()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
var i = 0
|
||||
|
||||
fun boo() = 1
|
||||
|
||||
fun f() {
|
||||
for (j in 0..2) {
|
||||
foo {
|
||||
i += j + boo()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun A.bar(): Int {
|
||||
for (u in 4..7) {
|
||||
foo {
|
||||
i += u + boo()
|
||||
}
|
||||
}
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
fun foo(f: () -> Unit) {
|
||||
f()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
a.f()
|
||||
if (a.i != 6) return "fail1: ${a.i}"
|
||||
if (a.bar() != 32) return "fail2: ${a.bar()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun foo() = "O"
|
||||
companion object {
|
||||
fun bar() = "K"
|
||||
}
|
||||
|
||||
val f = { foo() + bar() }
|
||||
}
|
||||
|
||||
fun box(): String = A().f()
|
||||
@@ -0,0 +1,35 @@
|
||||
package foo
|
||||
|
||||
class A(val a: String) {
|
||||
fun A.foo() = { a + this.a + this@foo.a + this@A.a }()
|
||||
fun bar(a: A) = this.foo() + " " + a.foo()
|
||||
|
||||
fun A.boo() = { arrayOf(this, this@boo, this@A) }()
|
||||
fun baz(a: A) = this.boo().stringify() + " " + a.boo().stringify()
|
||||
|
||||
fun Array<A>.stringify(): String {
|
||||
var result = ""
|
||||
for (a in this) {
|
||||
result += a.a
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A("a")
|
||||
val b = A("b")
|
||||
|
||||
assertEquals("aaaa aaaa", a.bar(a))
|
||||
assertEquals("aaaa bbba", a.bar(b))
|
||||
assertEquals("bbbb aaab", b.bar(a))
|
||||
assertEquals("bbbb bbbb", b.bar(b))
|
||||
|
||||
assertEquals("aaa aaa", a.baz(a))
|
||||
assertEquals("aaa bba", a.baz(b))
|
||||
assertEquals("bbb aab", b.baz(a))
|
||||
assertEquals("bbb bbb", b.baz(b))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package foo
|
||||
|
||||
// HACKS
|
||||
|
||||
@native
|
||||
const val ROOT = "Kotlin.modules.JS_TESTS"
|
||||
@native
|
||||
const val PATH_TO_F_CREATOR = "foo.B.far\$f"
|
||||
@native
|
||||
const val PATH_TO_G_CREATOR = "foo.B.gar\$f"
|
||||
|
||||
@native("$ROOT.$PATH_TO_F_CREATOR")
|
||||
val F_CREATOR: Any = noImpl
|
||||
@native("$ROOT.$PATH_TO_G_CREATOR")
|
||||
val G_CREATOR: Any = noImpl
|
||||
|
||||
|
||||
// Test
|
||||
|
||||
open class A {
|
||||
fun foo() = "A::foo"
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
fun boo() = "B::boo"
|
||||
|
||||
val far = { foo() }
|
||||
val gar = { boo() }
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
val f = b.far
|
||||
val g = b.gar
|
||||
|
||||
assertEquals("A::foo", f())
|
||||
assertEquals("B::boo", g())
|
||||
|
||||
val fs = F_CREATOR.toString()
|
||||
val gs = G_CREATOR.toString().replaceAll("boo", "foo")
|
||||
|
||||
assertEquals(gs, fs)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// Helpers
|
||||
|
||||
@native
|
||||
fun String.replace(regexp: RegExp, replacement: String): String = noImpl
|
||||
|
||||
fun String.replaceAll(regexp: String, replacement: String): String = replace(RegExp(regexp, "g"), replacement)
|
||||
|
||||
@native
|
||||
class RegExp(regexp: String, flags: String)
|
||||
@@ -0,0 +1,63 @@
|
||||
// KT-2388
|
||||
package foo
|
||||
|
||||
// workaround for Rhino
|
||||
class Done(val i: Int)
|
||||
|
||||
var done = Done(0)
|
||||
|
||||
object foo {
|
||||
var result = "FAIL"
|
||||
|
||||
val lambda = {
|
||||
result = "foo.lambda OK"
|
||||
done = Done(3)
|
||||
}
|
||||
|
||||
val extLambda: Done.() -> Unit = {
|
||||
result = "foo.extLambda OK"
|
||||
done = this
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
var result = "FAIL"
|
||||
|
||||
val lambda = {
|
||||
result = "Foo::lambda OK"
|
||||
done = Done(-7)
|
||||
}
|
||||
|
||||
val extLambda: Done.() -> Unit = {
|
||||
result = "Foo::extLambda OK"
|
||||
done = this
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = foo.lambda
|
||||
val b = foo.extLambda
|
||||
|
||||
val f = Foo()
|
||||
val c = f.lambda
|
||||
val d = f.extLambda
|
||||
|
||||
a()
|
||||
if (foo.result != "foo.lambda OK") return "foo.result = \"${foo.result}\", but expected \"foo.lambda OK\""
|
||||
if (done.i != 3) return "done.i = ${done.i}, but expected 3"
|
||||
|
||||
Done(23).b()
|
||||
if (foo.result != "foo.extLambda OK") return "foo.result = \"${foo.result}\", but expected \"foo.extLambda OK\""
|
||||
if (done.i != 23) return "done.i = ${done.i}, but expected 23"
|
||||
|
||||
|
||||
c()
|
||||
if (f.result != "Foo::lambda OK") return "a.result = \"${f.result}\", but expected \"Foo::lambda OK\""
|
||||
if (done.i != -7) return "done.i = ${done.i}, but expected -7"
|
||||
|
||||
Done(71).d()
|
||||
if (f.result != "Foo::extLambda OK") return "a.result = \"${f.result}\", but expected \"Foo::extLambda OK\""
|
||||
if (done.i != 71) return "done.i = ${done.i}, but expected 71"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// KT-4600 Generated wrong code when capturing `this` in extension function inside a method
|
||||
|
||||
package foo
|
||||
|
||||
public class Foo(val trigger: () -> Any) {
|
||||
fun test() = myRun { trigger() };
|
||||
}
|
||||
|
||||
fun box() = Foo({ "OK" }).test()
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
class B(val b: String)
|
||||
|
||||
class A(val a: String) {
|
||||
fun B.A() = { a + b }
|
||||
|
||||
fun foo(a: B) = a.A()()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val bar = A("bar")
|
||||
val baz = B("baz")
|
||||
|
||||
val r = bar.foo(baz)
|
||||
if (r != "barbaz") return "$r";
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// KT-4207 Closure this doesn't work in JS backend
|
||||
|
||||
package foo
|
||||
|
||||
fun String.foo() = { this }
|
||||
|
||||
class A {
|
||||
fun foo() = { this }
|
||||
val ok = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if ("OK".foo()() != "OK") return "\"OK\".foo()() != \"OK\""
|
||||
if (A().foo()().ok != "OK") return "A().foo()().ok != \"OK\""
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
object A {
|
||||
val x = 23
|
||||
val y = { x }
|
||||
fun foo() = { x }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(23, A.foo()())
|
||||
assertEquals(23, A.y())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
class Foo {
|
||||
val o = "O"
|
||||
val k = "K"
|
||||
fun test(): String {
|
||||
fun bar() = o
|
||||
fun Int.baz() = k + this
|
||||
|
||||
val boo = { k }
|
||||
val cux: Int.()->String = { o + this }
|
||||
|
||||
return bar() + 17.baz() + 23.cux() + boo()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Foo().test()
|
||||
if (a != "OK17O23K") return "$a"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package foo
|
||||
|
||||
val f = true
|
||||
|
||||
fun box(): String {
|
||||
val bar = "test "
|
||||
val boo = "another "
|
||||
|
||||
fun baz(): String {
|
||||
var result = bar
|
||||
|
||||
if (f) {
|
||||
val bar = 42
|
||||
result += bar
|
||||
|
||||
val boo = 7
|
||||
result += boo
|
||||
}
|
||||
|
||||
result += boo
|
||||
result += bar
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
val r = baz()
|
||||
if (r != "test 427another test ") return r;
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
val f = true
|
||||
|
||||
fun box(): String {
|
||||
var bar = ""
|
||||
var boo = 23
|
||||
|
||||
fun baz() {
|
||||
bar += "test "
|
||||
|
||||
if (f) {
|
||||
val v1 = 42
|
||||
var bar = 12
|
||||
bar += v1
|
||||
|
||||
val v2 = 7
|
||||
var boo = ""
|
||||
boo += v2
|
||||
}
|
||||
|
||||
boo += 7
|
||||
bar += "text"
|
||||
}
|
||||
|
||||
baz()
|
||||
if (bar != "test text") return "bar != \"test text\", bar = \"$bar\"";
|
||||
if (boo != 30) return "boo != 61, boo = $boo";
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user