tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
open class A {
|
||||
var f: String = "OK"
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val b = B()
|
||||
return (b::f).get()
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
companion object {
|
||||
fun ok() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = (A.Companion::ok)()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
enum class E {
|
||||
A, B;
|
||||
|
||||
fun foo() = this.name
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = E.A::foo
|
||||
val ef = E::foo
|
||||
|
||||
if (f() != "A") return "Fail 1: ${f()}"
|
||||
if (f == E.B::foo) return "Fail 2"
|
||||
if (ef != E::foo) return "Fail 3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
backend.native/tests/external/codegen/box/callableReference/bound/equals/nullableReceiverInEquals.kt
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// See https://youtrack.jetbrains.com/issue/KT-14938
|
||||
// WITH_REFLECT
|
||||
|
||||
class A
|
||||
|
||||
val a = A()
|
||||
val aa = A()
|
||||
|
||||
fun A?.foo() {}
|
||||
|
||||
var A?.bar: Int
|
||||
get() = 42
|
||||
set(value) {}
|
||||
|
||||
val aFoo = a::foo
|
||||
val A_foo = A::foo
|
||||
val nullFoo = null::foo
|
||||
|
||||
val aBar = a::bar
|
||||
val A_bar = A::bar
|
||||
val nullBar = null::bar
|
||||
|
||||
fun box(): String =
|
||||
when {
|
||||
nullFoo != null::foo -> "Bound extension refs with same receiver SHOULD be equal"
|
||||
nullFoo == aFoo -> "Bound extension refs with different receivers SHOULD NOT be equal"
|
||||
nullFoo == A_foo -> "Bound extension ref with receiver 'null' SHOULD NOT be equal to free ref"
|
||||
|
||||
nullBar != null::bar -> "Bound extension property refs with same receiver SHOULD be equal"
|
||||
nullBar == aBar -> "Bound extension property refs with different receivers SHOULD NOT be equal"
|
||||
nullBar == A_bar -> "Bound extension property ref with receiver 'null' SHOULD NOT be equal to free property ref"
|
||||
|
||||
else -> "OK"
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class C {
|
||||
var prop = 42
|
||||
}
|
||||
|
||||
val C_propReflect = C::class.memberProperties.find { it.name == "prop" } as? KMutableProperty1 ?: throw AssertionError()
|
||||
val C_prop = C::prop
|
||||
val cProp = C()::prop
|
||||
|
||||
fun box() =
|
||||
when {
|
||||
C_prop.getter != C_prop.getter -> "C_prop.getter != C_prop.getter"
|
||||
C_propReflect.getter != C_propReflect.getter -> "C_propReflect.getter != C_propReflect.getter"
|
||||
cProp.getter != cProp.getter -> "cProp.getter != cProp.getter"
|
||||
|
||||
cProp.getter == C_prop.getter -> "cProp.getter == C_prop.getter"
|
||||
C_prop.getter == cProp.getter -> "C_prop.getter == cProp.getter"
|
||||
cProp.getter == C_propReflect.getter -> "cProp.getter == C_propReflect.getter"
|
||||
C_propReflect.getter == cProp.getter -> "C_propReflect.getter == cProp.getter"
|
||||
|
||||
// TODO https://youtrack.jetbrains.com/issue/KT-13490
|
||||
// cProp.getter != C()::prop.getter -> "cProp.getter != C()::prop.getter"
|
||||
// cProp.setter != C()::prop.setter -> "cProp.setter != C()::prop.setter"
|
||||
|
||||
else -> "OK"
|
||||
}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
package test
|
||||
|
||||
class A {
|
||||
fun foo() {}
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
val a = A()
|
||||
val aa = A()
|
||||
|
||||
val aFoo = a::foo
|
||||
val aBar = a::bar
|
||||
val aaFoo = aa::foo
|
||||
val A_foo = A::foo
|
||||
|
||||
fun box(): String =
|
||||
when {
|
||||
aFoo != a::foo -> "Bound refs with same receiver SHOULD be equal"
|
||||
aFoo == aBar -> "Bound refs to different members SHOULD NOT be equal"
|
||||
aFoo == aaFoo -> "Bound refs with different receiver SHOULD NOT be equal"
|
||||
aFoo == A_foo -> "Bound ref SHOULD NOT be equal to free ref"
|
||||
|
||||
else -> "OK"
|
||||
}
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class C {
|
||||
fun foo() {}
|
||||
val bar = 42
|
||||
}
|
||||
|
||||
val C_fooReflect = C::class.functions.find { it.name == "foo" }!!
|
||||
val C_foo = C::foo
|
||||
val cFoo = C()::foo
|
||||
|
||||
val C_barReflect = C::class.memberProperties.find { it.name == "bar" }!!
|
||||
val C_bar = C::bar
|
||||
val cBar= C()::bar
|
||||
|
||||
val Any.className: String
|
||||
get() = this::class.qualifiedName!!
|
||||
|
||||
fun box(): String =
|
||||
when {
|
||||
C_fooReflect != C_foo -> "C_fooReflect != C_foo, ${C_fooReflect.className}"
|
||||
C_foo != C_fooReflect -> "C_foo != C_fooReflect, ${C_foo.className}"
|
||||
C_fooReflect == cFoo -> "C_fooReflect == cFoo, ${C_fooReflect.className}"
|
||||
cFoo == C_fooReflect -> "cFoo == C_fooReflect, ${cFoo.className}"
|
||||
C_barReflect != C_bar -> "C_barReflect != C_bar, ${C_barReflect.className}"
|
||||
C_bar != C_barReflect -> "C_bar != C_barReflect, ${C_bar.className}"
|
||||
C_barReflect == cBar -> "C_barReflect == cBar, ${C_barReflect.className}"
|
||||
cBar == C_barReflect -> "cBar == C_barReflect, ${cBar.className}"
|
||||
else -> "OK"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
inline fun foo(x: () -> String) = x()
|
||||
|
||||
fun String.id() = this
|
||||
|
||||
fun box() = foo("OK"::id)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
inline fun go(f: () -> String) = f()
|
||||
|
||||
fun String.id(): String = this
|
||||
|
||||
fun box(): String {
|
||||
val x = "OK"
|
||||
return go(x::id)
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
var state = 0
|
||||
val name = (state++)::toString.name
|
||||
if (name != "toString") return "Fail 1: $name"
|
||||
if (state != 1) return "Fail 2: $state"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun <T> get(t: T): () -> String {
|
||||
return t::toString
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (get(null).invoke() != "null") return "Fail null"
|
||||
|
||||
return get("OK").invoke()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//WITH_RUNTIME
|
||||
fun box(): String {
|
||||
val a = intArrayOf(1, 2)
|
||||
val b = arrayOf("OK")
|
||||
if ((a::component2)() != 2) {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
if ((a::get)(1) != 2) {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
return (b::get)(0)
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
class A(var v: Int) {
|
||||
fun f(x: Int) = x * v
|
||||
}
|
||||
|
||||
fun A.g(x: Int) = x * f(x);
|
||||
|
||||
var A.w: Int
|
||||
get() = 1000 * v
|
||||
set(c: Int) {
|
||||
v = c + 10
|
||||
}
|
||||
|
||||
object F {
|
||||
var u = 0
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A(5)
|
||||
|
||||
val av = a::v
|
||||
if (av() != 5) return "fail1: ${av()}"
|
||||
if (av.get() != 5) return "fail2: ${av.get()}"
|
||||
av.set(7)
|
||||
if (a.v != 7) return "fail3: ${a.v}"
|
||||
|
||||
val af = a::f
|
||||
if (af(10) != 70) return "fail4: ${af(10)}"
|
||||
|
||||
val ag = a::g
|
||||
if (ag(10) != 700) return "fail5: ${ag(10)}"
|
||||
|
||||
val aw = a::w
|
||||
if (aw() != 7000) return "fail6: ${aw()}"
|
||||
if (aw.get() != 7000) return "fail7: ${aw.get()}"
|
||||
aw.set(5)
|
||||
if (a.v != 15) return "fail8: ${a.v}"
|
||||
|
||||
val fu = F::u
|
||||
if (fu() != 0) return "fail9: ${fu()}"
|
||||
if (fu.get() != 0) return "fail10: ${fu.get()}"
|
||||
fu.set(8)
|
||||
if (F.u != 8) return "fail11: ${F.u}"
|
||||
|
||||
val x = 100
|
||||
|
||||
fun A.lf() = v * x;
|
||||
val alf = a::lf
|
||||
if (alf() != 1500) return "fail9: ${alf()}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
val String?.ok: String
|
||||
get() = "OK"
|
||||
|
||||
fun box() = (null::ok).get()
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
object Singleton {
|
||||
fun ok() = "OK"
|
||||
}
|
||||
|
||||
fun box() = (Singleton::ok)()
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
fun Boolean.foo() = 1
|
||||
fun Byte.foo() = 2
|
||||
fun Short.foo() = 3
|
||||
fun Int.foo() = 4
|
||||
fun Long.foo() = 5
|
||||
fun Char.foo() = 6
|
||||
fun Float.foo() = 7
|
||||
fun Double.foo() = 8
|
||||
|
||||
fun testRef(name: String, f: () -> Int, expected: Int) {
|
||||
val actual = f()
|
||||
if (actual != expected) throw AssertionError("$name: $actual != $expected")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testRef("Boolean", true::foo, 1)
|
||||
testRef("Byte", 1.toByte()::foo, 2)
|
||||
testRef("Short", 1.toShort()::foo, 3)
|
||||
testRef("Int", 1::foo, 4)
|
||||
testRef("Long", 1L::foo, 5)
|
||||
testRef("Char", '1'::foo, 6)
|
||||
testRef("Float", 1.0F::foo, 7)
|
||||
testRef("Double", 1.0::foo, 8)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun box(): String {
|
||||
val f = "KOTLIN"::get
|
||||
return "${f(1)}${f(0)}"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
val f = "kotlin"::length
|
||||
val result = f.get()
|
||||
return if (result == 6) "OK" else "Fail: $result"
|
||||
}
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// FILE: A.java
|
||||
|
||||
public class A {
|
||||
private final String field;
|
||||
|
||||
public A(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public CharSequence getFoo() { return field; }
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
with (A("OK")) {
|
||||
val k = foo::toString
|
||||
return k()
|
||||
}
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
abstract class A {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String = (A::foo)(B())
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
if ((Boolean::not)(true) != false) return "Fail 1"
|
||||
if ((Boolean::not)(false) != true) return "Fail 2"
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
class A {
|
||||
fun foo(k: Int) = k
|
||||
|
||||
fun result() = (A::foo)(this, 111)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().result()
|
||||
if (result != 111) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
fun o() = 111
|
||||
fun k(k: Int) = k
|
||||
}
|
||||
|
||||
fun A.foo() = (A::o)(this) + (A::k)(this, 222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().foo()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
return x(A())
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
fun foo(result: String) = result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
return x(A(), "OK")
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
var result = "Fail"
|
||||
|
||||
fun foo() {
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
x(a)
|
||||
return a.result
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
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
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
var result = "OK"
|
||||
}
|
||||
|
||||
fun box() = (::A)().result
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class A(val result: String)
|
||||
|
||||
fun box() = (::A)("OK").result
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
enum class E {
|
||||
ENTRY
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = E::valueOf
|
||||
val result = f("ENTRY")
|
||||
return if (result == E.ENTRY) "OK" else "Fail $result"
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class A
|
||||
|
||||
fun box() = if ((A::equals)(A(), A())) "Fail" else "OK"
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
fun result() = (A::foo)(this, "OK")
|
||||
}
|
||||
|
||||
fun A.foo(x: String) = x
|
||||
|
||||
fun box() = A().result()
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
class A
|
||||
|
||||
fun A.foo() = (A::bar)(this, "OK")
|
||||
|
||||
fun A.bar(x: String) = x
|
||||
|
||||
fun box() = A().foo()
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class A
|
||||
|
||||
fun A.foo() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
return x(A())
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class A
|
||||
|
||||
fun A.foo(result: String) = result
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
return x(A(), "OK")
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
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
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
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")
|
||||
return a.result
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun <T, R> foo(x: T): R = TODO()
|
||||
fun <T> fooReturnInt(x: T): Int = 1
|
||||
|
||||
inline fun <reified T, reified R> check(x: T, y: R, f: (T) -> R, tType: String, rType: String) {
|
||||
assertEquals(tType, T::class.simpleName)
|
||||
assertEquals(rType, R::class.simpleName)
|
||||
}
|
||||
|
||||
inline fun <reified T, reified R> check(f: (T) -> R, g: (T) -> R, tType: String, rType: String) {
|
||||
assertEquals(tType, T::class.simpleName)
|
||||
assertEquals(rType, R::class.simpleName)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check("", 1, ::foo, "String", "Int")
|
||||
check("", 1, ::fooReturnInt, "String", "Int")
|
||||
check("", "", ::fooReturnInt, "String", "Any")
|
||||
|
||||
check(Int::toString, ::foo, "Int", "String")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun <T, R> foo(x: T): R = TODO()
|
||||
|
||||
inline fun <reified T, reified R> bar(x: T, y: R, f: (T) -> R, tType: String, rType: String): Pair<T, R?> {
|
||||
assertEquals(tType, T::class.simpleName)
|
||||
assertEquals(rType, R::class.simpleName)
|
||||
return Pair(x, y)
|
||||
}
|
||||
|
||||
data class Pair<A, B>(val a: A, val b: B)
|
||||
|
||||
fun box(): String {
|
||||
bar(1, "", ::foo, "Int", "String")
|
||||
|
||||
val s1: Pair<Int, String?> = bar(1, "", ::foo, "Int", "String")
|
||||
val (a: Int, b: String?) = bar(1, "", ::foo, "Int", "String")
|
||||
|
||||
val ns: String? = null
|
||||
bar(ns, ns, ::foo, "String", "String")
|
||||
|
||||
val s2: Pair<Int?, String?> = bar(null, null, ::foo, "Int", "String")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo(x: Int?) {}
|
||||
fun foo(y: String?) {}
|
||||
fun foo(z: Boolean) {}
|
||||
|
||||
inline fun <reified T> bar(f: (T) -> Unit, tType: String): T? {
|
||||
assertEquals(tType, T::class.simpleName)
|
||||
return null
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a1: Int? = bar(::foo, "Int")
|
||||
val a2: String? = bar(::foo, "String")
|
||||
val a3: Boolean? = bar<Boolean>(::foo, "Boolean")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class A<T>(val t: T) {
|
||||
fun foo(): T = t
|
||||
}
|
||||
|
||||
fun box() = (A<String>::foo)(A("OK"))
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class Wrapper<T>(val value: T)
|
||||
|
||||
fun box(): String {
|
||||
val ls = listOf("OK").map(::Wrapper)
|
||||
return ls[0].value
|
||||
}
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.jvm.internal.FunctionBase
|
||||
|
||||
fun test(f: Function<*>, arity: Int) {
|
||||
assertEquals(arity, (f as FunctionBase).getArity())
|
||||
}
|
||||
|
||||
fun foo(s: String, i: Int) {}
|
||||
class A {
|
||||
fun bar(s: String, i: Int) {}
|
||||
}
|
||||
fun Double.baz(s: String, i: Int) {}
|
||||
|
||||
fun box(): String {
|
||||
test(::foo, 2)
|
||||
test(A::bar, 3)
|
||||
test(Double::baz, 3)
|
||||
|
||||
test(::box, 0)
|
||||
|
||||
fun local(x: Int) {}
|
||||
test(::local, 1)
|
||||
|
||||
test(fun(s: String) = s, 1)
|
||||
test(fun(){}, 0)
|
||||
test({}, 0)
|
||||
test({x: Int -> x}, 1)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
inner class Inner {
|
||||
val o = 111
|
||||
val k = 222
|
||||
}
|
||||
|
||||
fun result() = (A::Inner)(this).o + (A::Inner)(this).k
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().result()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
inner class Inner {
|
||||
val o = 111
|
||||
val k = 222
|
||||
}
|
||||
}
|
||||
|
||||
fun A.foo() = (A::Inner)(this).o + (A::Inner)(this).k
|
||||
|
||||
fun box(): String {
|
||||
val result = A().foo()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
inner class Inner {
|
||||
val o = 111
|
||||
val k = 222
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = (A::Inner)((::A)()).o + (A::Inner)(A()).k
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
inner class Inner(val result: Int)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = (A::Inner)((::A)(), 111).result + (A::Inner)(A(), 222).result
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// KT-5123
|
||||
|
||||
import java.util.Collections
|
||||
import java.util.ArrayList
|
||||
|
||||
fun box(): String {
|
||||
val numbers = ArrayList<Int>()
|
||||
numbers.add(1)
|
||||
numbers.add(2)
|
||||
numbers.add(3)
|
||||
(Collections::rotate)(numbers, 1)
|
||||
return if ("$numbers" == "[3, 1, 2]") "OK" else "Fail $numbers"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class Outer {
|
||||
val result = "OK"
|
||||
|
||||
inner class Inner {
|
||||
fun foo() = result
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = Outer.Inner::foo
|
||||
return f(Outer().Inner())
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
class Local {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
val ref = Local::foo
|
||||
return ref(Local())
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun changeToOK() { result = "OK" }
|
||||
|
||||
val ok = ::changeToOK
|
||||
ok()
|
||||
return result
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
class A {
|
||||
val result = "OK"
|
||||
}
|
||||
|
||||
return (::A)().result
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
class A {
|
||||
var result: String = "Fail";
|
||||
init {
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
return (::A)().result
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
interface Named {
|
||||
val name: String
|
||||
}
|
||||
|
||||
enum class E : Named {
|
||||
OK
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return E.OK.name
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
fun A.foo() = "OK"
|
||||
return (A::foo)(A())
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
class A
|
||||
fun A.foo() = "OK"
|
||||
return (A::foo)((::A)())
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
fun box(): String {
|
||||
fun Int.is42With(that: Int) = this + 2 * that == 42
|
||||
return if ((Int::is42With)(16, 13)) "OK" else "Fail"
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun A.ext() { result = "OK" }
|
||||
|
||||
val f = A::ext
|
||||
f(A())
|
||||
return result
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
class Id<T> {
|
||||
fun invoke(t: T) = t
|
||||
}
|
||||
|
||||
val ref = Id<String>::invoke
|
||||
return ref(Id<String>(), "OK")
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
fun box(): String {
|
||||
val result = "OK"
|
||||
|
||||
class Local {
|
||||
fun foo() = result
|
||||
}
|
||||
|
||||
val member = Local::foo
|
||||
val instance = Local()
|
||||
return member(instance)
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
fun OK() {}
|
||||
|
||||
return ::OK.name
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
fun foo(): String {
|
||||
fun bar() = "OK"
|
||||
val ref = ::bar
|
||||
return ref()
|
||||
}
|
||||
|
||||
val ref = ::foo
|
||||
return ref()
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
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)
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun box(): String {
|
||||
fun foo() = "OK"
|
||||
return (::foo)()
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
val result = "OK"
|
||||
|
||||
fun foo() = result
|
||||
|
||||
return (::foo)()
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
fun box(): String {
|
||||
fun foo(s: String) = s
|
||||
return (::foo)("OK")
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
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"
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
class Nested {
|
||||
val o = 111
|
||||
val k = 222
|
||||
}
|
||||
|
||||
fun result() = (::Nested)().o + (A::Nested)().k
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().result()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
class Nested {
|
||||
val result = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = (A::Nested)().result
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
class Nested(val result: String)
|
||||
}
|
||||
|
||||
fun box() = (A::Nested)("OK").result
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
private fun <T> upcast(value: T): T = value
|
||||
|
||||
fun box(): String {
|
||||
upcast<(Int)->ByteArray>(::ByteArray)(10)
|
||||
upcast<(Int)->IntArray>(::IntArray)(10)
|
||||
upcast<(Int)->ShortArray>(::ShortArray)(10)
|
||||
upcast<(Int)->LongArray>(::LongArray)(10)
|
||||
upcast<(Int)->DoubleArray>(::DoubleArray)(10)
|
||||
upcast<(Int)->FloatArray>(::FloatArray)(10)
|
||||
upcast<(Int)->BooleanArray>(::BooleanArray)(10)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
fun foo(): String = "foo1"
|
||||
fun foo(i: Int): String = "foo2"
|
||||
|
||||
val f1: () -> String = ::foo
|
||||
val f2: (Int) -> String = ::foo
|
||||
|
||||
fun foo1() {}
|
||||
fun foo2(i: Int) {}
|
||||
|
||||
fun bar(f: () -> Unit): String = "bar1"
|
||||
fun bar(f: (Int) -> Unit): String = "bar2"
|
||||
|
||||
fun box(): String {
|
||||
val x1 = f1()
|
||||
if (x1 != "foo1") return "Fail 1: $x1"
|
||||
|
||||
val x2 = f2(0)
|
||||
if (x2 != "foo2") return "Fail 2: $x2"
|
||||
|
||||
val y1 = bar(::foo1)
|
||||
if (y1 != "bar1") return "Fail 3: $y1"
|
||||
|
||||
val y2 = bar(::foo2)
|
||||
if (y2 != "bar2") return "Fail 4: $y2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class A {
|
||||
val x = 1
|
||||
fun x(): String = "OK"
|
||||
}
|
||||
|
||||
val f1: KProperty1<A, Int> = A::x
|
||||
val f2: (A) -> String = A::x
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
|
||||
val x1 = f1.get(a)
|
||||
if (x1 != 1) return "Fail 1: $x1"
|
||||
|
||||
return f2(a)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
private fun foo() = "OK"
|
||||
|
||||
fun bar() = (A::foo)(this)
|
||||
}
|
||||
|
||||
fun box() = A().bar()
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun sort(list: MutableList<String>, comparator: (String, String) -> Int) {
|
||||
list.sortWith(Comparator(comparator))
|
||||
}
|
||||
|
||||
fun compare(s1: String, s2: String) = s1.compareTo(s2)
|
||||
|
||||
fun box(): String {
|
||||
val l = mutableListOf("d", "b", "c", "e", "a")
|
||||
sort(l, ::compare)
|
||||
if (l != listOf("a", "b", "c", "d", "e")) return "Fail: $l"
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
fun baz(i: Int) = i
|
||||
fun <T> bar(x: T): T = x
|
||||
|
||||
fun nullableFun(): ((Int) -> Int)? = null
|
||||
|
||||
fun box(): String {
|
||||
val x1: (Int) -> Int = bar(if (true) ::baz else ::baz)
|
||||
val x2: (Int) -> Int = bar(nullableFun() ?: ::baz)
|
||||
val x3: (Int) -> Int = bar(::baz ?: ::baz)
|
||||
|
||||
val i = 0
|
||||
val x4: (Int) -> Int = bar(when (i) {
|
||||
10 -> ::baz
|
||||
20 -> ::baz
|
||||
else -> ::baz
|
||||
})
|
||||
|
||||
val x5: (Int) -> Int = bar(::baz!!)
|
||||
|
||||
if (x1(1) != 1) return "fail 1"
|
||||
if (x2(1) != 1) return "fail 2"
|
||||
if (x3(1) != 1) return "fail 3"
|
||||
if (x4(1) != 1) return "fail 4"
|
||||
if (x5(1) != 1) return "fail 5"
|
||||
|
||||
if ((if (true) ::baz else ::baz)(1) != 1) return "fail 6"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun foo(o: Int, k: Int) = o + k
|
||||
|
||||
class A {
|
||||
fun bar() = (::foo)(111, 222)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
fun foo(o: Int, k: Int) = o + k
|
||||
|
||||
class A
|
||||
|
||||
fun A.bar() = (::foo)(111, 222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun foo() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
val x = ::foo
|
||||
return x()
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(x: String) = x
|
||||
|
||||
fun box(): String {
|
||||
val x = ::foo
|
||||
return x("OK")
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
var result = "Fail"
|
||||
|
||||
fun foo() {
|
||||
result = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = ::foo
|
||||
x()
|
||||
return result
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
var result = "Fail"
|
||||
|
||||
fun foo(newResult: String) {
|
||||
result = newResult
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = ::foo
|
||||
x("OK")
|
||||
return result
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
interface T {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
class B : T {
|
||||
inner class C {
|
||||
fun bar() = (T::foo)(this@B)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = B().C().bar()
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
class B : A {
|
||||
override fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box() = (A::foo)(B())
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
abstract class Base {
|
||||
val result = "OK"
|
||||
}
|
||||
|
||||
class Derived : Base()
|
||||
|
||||
fun box(): String {
|
||||
return (Base::result).get(Derived())
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val four: Int by NumberDecrypter
|
||||
|
||||
class A {
|
||||
val two: Int by NumberDecrypter
|
||||
}
|
||||
|
||||
object NumberDecrypter {
|
||||
operator fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
|
||||
"four" -> 4
|
||||
"two" -> 2
|
||||
else -> throw AssertionError()
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
var result: String by Delegate
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
enum class E {
|
||||
I
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val i = (E::name).get(E.I)
|
||||
if (i != "I") return "Fail $i"
|
||||
val n = (E::ordinal).get(E.I)
|
||||
if (n != 0) return "Fail $n"
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
val Array<String>.firstElement: String get() = get(0)
|
||||
|
||||
fun box(): String {
|
||||
val p = Array<String>::firstElement
|
||||
return p.get(arrayOf("OK", "Fail"))
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
//For KT-6020
|
||||
import kotlin.reflect.KProperty1
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class Value<T>(var value: T = null as T, var text: String? = null)
|
||||
|
||||
val <T> Value<T>.additionalText by DVal(Value<T>::text) //works
|
||||
|
||||
val <T> Value<T>.additionalValue by DVal(Value<T>::value) //not work
|
||||
|
||||
class DVal<T, R, P: KProperty1<T, R>>(val kmember: P) {
|
||||
operator fun getValue(t: T, p: KProperty<*>): R {
|
||||
return kmember.get(t)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p = Value("O", "K")
|
||||
return p.additionalValue + p.additionalText
|
||||
}
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
var state = ""
|
||||
|
||||
var topLevel: Int
|
||||
get() {
|
||||
state += "1"
|
||||
return 42
|
||||
}
|
||||
set(value) {
|
||||
throw AssertionError("Nooo")
|
||||
}
|
||||
|
||||
class A {
|
||||
val member: String
|
||||
get() {
|
||||
state += "2"
|
||||
return "42"
|
||||
}
|
||||
}
|
||||
|
||||
val A.ext: Any
|
||||
get() {
|
||||
state += "3"
|
||||
return this
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
(::topLevel)()
|
||||
(A::member)(A())
|
||||
(A::ext)(A())
|
||||
return if (state == "123") "OK" else "Fail $state"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// Name of the getter should be 'getaBcde' according to JavaBean conventions
|
||||
var aBcde: Int = 239
|
||||
|
||||
fun box(): String {
|
||||
val x = (::aBcde).get()
|
||||
if (x != 239) return "Fail x: $x"
|
||||
|
||||
(::aBcde).set(42)
|
||||
|
||||
val y = (::aBcde).get()
|
||||
if (y != 42) return "Fail y: $y"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
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())
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// KT-12044 Assertion "Rewrite at slice LEXICAL_SCOPE" for 'if' with property references
|
||||
|
||||
fun box(): String {
|
||||
data class Pair<F, S>(val first: F, val second: S)
|
||||
val (x, y) =
|
||||
Pair(1,
|
||||
if (1 == 1)
|
||||
Pair<String, String>::first
|
||||
else
|
||||
Pair<String, String>::second)
|
||||
return y.get(Pair("OK", "Fail"))
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class Foo {
|
||||
protected var x = 0
|
||||
|
||||
fun getX() = Foo::x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = Foo().getX()
|
||||
val foo = Foo()
|
||||
x.set(foo, 42)
|
||||
return if (x.get(foo) == 42) "OK" else "Fail"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
data class Foo(var bar: Int?)
|
||||
|
||||
fun box(): String {
|
||||
val receiver = Foo(1)
|
||||
Foo::bar.set(receiver, null)
|
||||
return if (receiver.bar == null) "OK" else "fail ${receiver.bar}"
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
var recivier : Any? = "fail"
|
||||
var value2 : Any? = "fail2"
|
||||
|
||||
var <T> T.bar : T
|
||||
get() = this
|
||||
set(value) { recivier = this; value2 = value}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
String?::bar.set(null, null)
|
||||
if (recivier != null) "fail 1: ${recivier}"
|
||||
if (value2 != null) "fail 2: ${value2}"
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
//WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
var methodVar = "OK"
|
||||
|
||||
fun localMethod() : String
|
||||
{
|
||||
return lazy { methodVar }::value.get()
|
||||
}
|
||||
|
||||
return localMethod()
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
class Test {
|
||||
private var iv = 1
|
||||
|
||||
public fun exec() {
|
||||
val t = object : Thread() {
|
||||
override fun run() {
|
||||
Test::iv.get(this@Test)
|
||||
Test::iv.set(this@Test, 2)
|
||||
}
|
||||
}
|
||||
t.start()
|
||||
t.join(1000)
|
||||
}
|
||||
|
||||
fun result() = if (iv == 2) "OK" else "Fail $iv"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t = Test()
|
||||
t.exec()
|
||||
return t.result()
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String =
|
||||
if (listOf("abc", "de", "f").map(String::length) == listOf(3, 2, 1)) "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