Move some tests from boxWithStdlib/ to box/

Move those tests which do not require neither stdlib nor reflect
This commit is contained in:
Alexander Udalov
2016-03-05 18:39:20 +03:00
committed by Alexander Udalov
parent 54a615fcd3
commit 20e36438e2
217 changed files with 1561 additions and 1397 deletions
@@ -1,11 +0,0 @@
operator fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
operator fun Array<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = Array<String>(1, { "" })
s[1, -1] = "O"
s[2, -2] += "K"
return s[-3, 3]
}
@@ -1,11 +0,0 @@
operator fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
operator fun Array<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = Array<String>(1, { "" })
s[1, -1] = "OK"
return s[-2, 2]
}
@@ -1,15 +0,0 @@
import java.util.Arrays.equals
fun box(): String {
val s = arrayOf("live", "long")
val t: Array<String> = s.clone()
if (!equals(s, t)) return "Fail string"
if (s === t) return "Fail string identity"
val ss = arrayOf(s, s)
val tt: Array<Array<String>> = ss.clone()
if (!equals(ss, tt)) return "Fail string[]"
if (ss === tt) return "Fail string[] identity"
return "OK"
}
@@ -1,37 +0,0 @@
import java.util.Arrays.equals
fun box(): String {
val i = intArrayOf(1, 2)
if (!equals(i, i.clone())) return "Fail int"
if (i.clone() === i) return "Fail int identity"
val j = longArrayOf(1L, 2L)
if (!equals(j, j.clone())) return "Fail long"
if (j.clone() === j) return "Fail long identity"
val s = shortArrayOf(1.toShort(), 2.toShort())
if (!equals(s, s.clone())) return "Fail short"
if (s.clone() === s) return "Fail short identity"
val b = byteArrayOf(1.toByte(), 2.toByte())
if (!equals(b, b.clone())) return "Fail byte"
if (b.clone() === b) return "Fail byte identity"
val c = charArrayOf('a', 'b')
if (!equals(c, c.clone())) return "Fail char"
if (c.clone() === c) return "Fail char identity"
val d = doubleArrayOf(1.0, -1.0)
if (!equals(d, d.clone())) return "Fail double"
if (d.clone() === d) return "Fail double identity"
val f = floatArrayOf(1f, -1f)
if (!equals(f, f.clone())) return "Fail float"
if (f.clone() === f) return "Fail float identity"
val z = booleanArrayOf(true, false)
if (!equals(z, z.clone())) return "Fail boolean"
if (z.clone() === z) return "Fail boolean identity"
return "OK"
}
@@ -1,9 +0,0 @@
fun test(y: Array<in Array<String>>) {
y[0] = kotlin.arrayOf("OK")
}
fun box() : String {
val x : Array<Array<*>> = kotlin.arrayOf(kotlin.arrayOf(1))
test(x)
return x[0][0] as String
}
@@ -1,10 +0,0 @@
fun box(): String {
val x : Array<Array<*>> = arrayOf(arrayOf(1))
val y : Array<in Array<String>> = x
if (y.size != 1) return "fail 1"
y[0] = arrayOf("OK")
return x[0][0] as String
}
@@ -1,9 +0,0 @@
fun box(): String {
val x = Array<Int>(5, { it } ).iterator()
var i = 0
while (x.hasNext()) {
if (x.next() != i) return "Fail $i"
i++
}
return "OK"
}
@@ -1,27 +0,0 @@
var result = 0
fun <T> Iterator<T>.foreach(action: (T) -> Unit) {
while (this.hasNext()) {
(action)(this.next())
}
}
fun <In, Out> Iterator<In>.select(f: (In) -> Out) : Iterator<Out> {
return Selector(this, f);
}
class Selector<In, Out>(val source: Iterator<In>, val f: (In) -> Out) : Iterator<Out> {
override fun hasNext(): Boolean = source.hasNext()
override fun next(): Out {
return (f)(source.next())
}
}
fun box(): String {
Array(4, { it + 1 }).iterator()
.select({i -> i * 10})
.foreach({k -> result += k})
if (result != 10+20+30+40) return "Fail: $result"
return "OK"
}
@@ -1,14 +0,0 @@
fun fill(dest : Array<in String>, v : String) {
dest[0] = v
}
fun box() : String {
//fun main(args : Array<String>) {
val s : String = "bar"
val any : Array<Any> = arrayOf(1, "foo", 1.234)
fill(any, s)
/* shouldn't throw
ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
*/
return "OK"
}
@@ -1,94 +0,0 @@
fun Array<String>.test1(): Array<String> {
val func = { i:Int -> this}
return func(1)
}
fun Array<String>.test1Nested(): Array<String> {
val func = { i: Int -> { this }()}
return func(1)
}
fun Array<String>.test2() : Array<String> {
class Z2() {
fun run(): Array<String> {
return this@test2
}
}
return Z2().run()
}
fun Array<String>.test2Nested() : Array<String> {
class Z2() {
fun run(): Array<String> {
class Z3 {
fun run(): Array<String> {
return this@test2Nested;
}
}
return Z3().run()
}
}
return Z2().run()
}
fun Array<String>.test3(): Array<String> {
fun local(): Array<String> {
return this@test3
}
return local()
}
fun Array<String>.test3Nested(): Array<String> {
fun local(): Array<String> {
fun local2(): Array<String> {
return this@test3Nested
}
return local2()
}
return local()
}
fun Array<String>.test4() : Array<String> {
return object {
fun run() : Array<String> {
return this@test4
}
}.run()
}
fun Array<String>.test4Nested() : Array<String> {
return object {
fun run() : Array<String> {
return object {
fun run() : Array<String> {
return this@test4Nested
}
}.run()
}
}.run()
}
fun Array<DoubleArray>.test1(): Array<DoubleArray> {
val func = { i: Int -> this}
return func(1)
}
fun box() : String {
val array = Array<String>(2, { i -> "${i}" })
if (array != array.test1()) return "fail 1"
if (array != array.test2()) return "fail 2"
if (array != array.test3()) return "fail 3"
if (array != array.test4()) return "fail 4"
if (array != array.test1Nested()) return "fail 1Nested"
if (array != array.test2Nested()) return "fail 2Nested"
if (array != array.test3Nested()) return "fail 3Nested"
if (array != array.test4Nested()) return "fail 4Nested"
val array2 = Array<DoubleArray>(2, { i -> DoubleArray(i) })
if (array2 != array2.test1()) return "fail on array of double []"
return "OK"
}
@@ -1,8 +0,0 @@
fun box(): String {
val array = intArrayOf(11, 12, 13)
val p = array.get(0)
if (p != 11) return "fail 1: $p"
val stringArray = arrayOf("OK", "FAIL")
return stringArray.get(0)
}
@@ -1,9 +0,0 @@
fun box() : String {
val data = Array<Array<Boolean>>(3) { Array<Boolean>(4, {false}) }
for(d in data) {
if(d.size != 4) return "fail"
for(b in d) if (b) return "fail"
}
return "OK"
}
@@ -1,21 +0,0 @@
fun testArray() {
Array<String>(5) { i ->
if (i == 3) return
i.toString()
}
throw AssertionError()
}
fun testIntArray() {
IntArray(5) { i ->
if (i == 3) return
i
}
throw AssertionError()
}
fun box(): String {
testArray()
testIntArray()
return "OK"
}
@@ -1,8 +0,0 @@
class A() {
class B(val i: Int) {
}
fun test() = Array<B> (10, { B(it) })
}
fun box() = if(A().test()[5].i == 5) "OK" else "fail"
@@ -1,56 +0,0 @@
interface ISized {
val size : Int
}
interface javaUtilIterator<T> : Iterator<T> {
fun remove() : Unit {
throw UnsupportedOperationException()
}
}
class MyIterator<T>(val array : ReadOnlyArray<T>) : javaUtilIterator<T> {
private var index = 0
override fun hasNext() : Boolean = index < array.size
override fun next() : T = array.get(index++)
}
interface ReadOnlyArray<out T> : ISized, Iterable<T> {
operator fun get(index : Int) : T
override fun iterator() : Iterator<T> = MyIterator<T>(this)
}
interface WriteOnlyArray<in T> : ISized {
operator fun set(index : Int, value : T) : Unit
operator fun set(from: Int, count: Int, value: T) {
for(i in from..from+count-1) {
set(i, value)
}
}
}
class MutableArray<T>(length: Int, init : (Int) -> T) : ReadOnlyArray<T>, WriteOnlyArray<T> {
private val array = Array<Any?>(length, init)
override fun get(index : Int) : T = array[index] as T
override fun set(index : Int, value : T) : Unit { array[index] = value }
override val size : Int
get() = array.size
}
fun box() : String {
var a = MutableArray<Int> (4, {0})
a [0] = 10
a.set(1, 2, 13)
a [3] = 40
a.iterator()
a.iterator().hasNext()
for(el in a) {
val fl = el
}
return "OK"
}
@@ -1,8 +0,0 @@
fun box() : String {
try {
return "OK"
}
finally {
null?.toString()
}
}
@@ -1,10 +0,0 @@
fun box() : String {
val s = "notA"
val id = when (s) {
"a" -> 1
else -> null
}
if (id == null) return "OK"
return "fail"
}
@@ -1,9 +0,0 @@
abstract class A {
abstract fun foo(): String
}
class B : A() {
override fun foo() = "OK"
}
fun box(): String = (A::foo)(B())
@@ -1,5 +0,0 @@
fun box(): String {
if ((Boolean::not)(true) != false) return "Fail 1"
if ((Boolean::not)(false) != true) return "Fail 2"
return "OK"
}
@@ -1,11 +0,0 @@
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"
}
@@ -1,12 +0,0 @@
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"
}
@@ -1,8 +0,0 @@
class A {
fun foo() = "OK"
}
fun box(): String {
val x = A::foo
return x(A())
}
@@ -1,8 +0,0 @@
class A {
fun foo(result: String) = result
}
fun box(): String {
val x = A::foo
return x(A(), "OK")
}
@@ -1,14 +0,0 @@
class A {
var result = "Fail"
fun foo() {
result = "OK"
}
}
fun box(): String {
val a = A()
val x = A::foo
x(a)
return a.result
}
@@ -1,14 +0,0 @@
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
}
@@ -1,5 +0,0 @@
class A {
var result = "OK"
}
fun box() = (::A)().result
@@ -1,3 +0,0 @@
class A(val result: String)
fun box() = (::A)("OK").result
@@ -1,9 +0,0 @@
enum class E {
ENTRY
}
fun box(): String {
val f = E::valueOf
val result = f("ENTRY")
return if (result == E.ENTRY) "OK" else "Fail $result"
}
@@ -1,3 +0,0 @@
class A
fun box() = if ((A::equals)(A(), A())) "Fail" else "OK"
@@ -1,7 +0,0 @@
class A {
fun result() = (A::foo)(this, "OK")
}
fun A.foo(x: String) = x
fun box() = A().result()
@@ -1,7 +0,0 @@
class A
fun A.foo() = (A::bar)(this, "OK")
fun A.bar(x: String) = x
fun box() = A().foo()
@@ -1,8 +0,0 @@
class A
fun A.foo() = "OK"
fun box(): String {
val x = A::foo
return x(A())
}
@@ -1,8 +0,0 @@
class A
fun A.foo(result: String) = result
fun box(): String {
val x = A::foo
return x(A(), "OK")
}
@@ -1,14 +0,0 @@
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
}
@@ -1,14 +0,0 @@
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
}
@@ -1,5 +0,0 @@
class A<T>(val t: T) {
fun foo(): T = t
}
fun box() = (A<String>::foo)(A("OK"))
@@ -1,14 +0,0 @@
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"
}
@@ -1,14 +0,0 @@
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"
}
@@ -1,12 +0,0 @@
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"
}
@@ -1,9 +0,0 @@
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"
}
@@ -1,13 +0,0 @@
// 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"
}
@@ -1,12 +0,0 @@
class Outer {
val result = "OK"
inner class Inner {
fun foo() = result
}
}
fun box(): String {
val f = Outer.Inner::foo
return f(Outer().Inner())
}
@@ -1,8 +0,0 @@
fun box(): String {
class Local {
fun foo() = "OK"
}
val ref = Local::foo
return ref(Local())
}
@@ -1,9 +0,0 @@
fun box(): String {
var result = "Fail"
fun changeToOK() { result = "OK" }
val ok = ::changeToOK
ok()
return result
}
@@ -1,7 +0,0 @@
fun box(): String {
class A {
val result = "OK"
}
return (::A)().result
}
@@ -1,10 +0,0 @@
fun box(): String {
class A {
var result: String = "Fail";
init {
result = "OK"
}
}
return (::A)().result
}
@@ -1,11 +0,0 @@
interface Named {
val name: String
}
enum class E : Named {
OK
}
fun box(): String {
return E.OK.name
}
@@ -1,6 +0,0 @@
class A
fun box(): String {
fun A.foo() = "OK"
return (A::foo)(A())
}
@@ -1,5 +0,0 @@
fun box(): String {
class A
fun A.foo() = "OK"
return (A::foo)((::A)())
}
@@ -1,4 +0,0 @@
fun box(): String {
fun Int.is42With(that: Int) = this + 2 * that == 42
return if ((Int::is42With)(16, 13)) "OK" else "Fail"
}
@@ -1,11 +0,0 @@
class A
fun box(): String {
var result = "Fail"
fun A.ext() { result = "OK" }
val f = A::ext
f(A())
return result
}
@@ -1,8 +0,0 @@
fun box(): String {
class Id<T> {
fun invoke(t: T) = t
}
val ref = Id<String>::invoke
return ref(Id<String>(), "OK")
}
@@ -1,11 +0,0 @@
fun box(): String {
val result = "OK"
class Local {
fun foo() = result
}
val member = Local::foo
val instance = Local()
return member(instance)
}
@@ -1,10 +0,0 @@
fun box(): String {
fun foo(): String {
fun bar() = "OK"
val ref = ::bar
return ref()
}
val ref = ::foo
return ref()
}
@@ -1,7 +0,0 @@
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)
@@ -1,4 +0,0 @@
fun box(): String {
fun foo() = "OK"
return (::foo)()
}
@@ -1,7 +0,0 @@
fun box(): String {
val result = "OK"
fun foo() = result
return (::foo)()
}
@@ -1,4 +0,0 @@
fun box(): String {
fun foo(s: String) = s
return (::foo)("OK")
}
@@ -1,15 +0,0 @@
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"
}
@@ -1,14 +0,0 @@
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"
}
@@ -1,7 +0,0 @@
class A {
class Nested {
val result = "OK"
}
}
fun box() = (A::Nested)().result
@@ -1,5 +0,0 @@
class A {
class Nested(val result: String)
}
fun box() = (A::Nested)("OK").result
@@ -1,13 +0,0 @@
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"
}
@@ -1,22 +0,0 @@
import kotlin.test.assertEquals
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 {
assertEquals("foo1", f1())
assertEquals("foo2", f2(0))
assertEquals("bar1", bar(::foo1))
assertEquals("bar2", bar(::foo2))
return "OK"
}
@@ -1,19 +0,0 @@
import kotlin.reflect.*
import kotlin.test.assertEquals
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()
assertEquals(1, f1.get(a))
assertEquals("OK", f2(a))
return "OK"
}
@@ -1,7 +0,0 @@
class A {
private fun foo() = "OK"
fun bar() = (A::foo)(this)
}
fun box() = A().bar()
@@ -1,19 +0,0 @@
import java.util.ArrayList
import java.util.Arrays
import java.util.Collections
import java.util.Comparator
fun sort(list: MutableList<String>, comparator: (String, String) -> Int) {
Collections.sort(list, object : Comparator<String> {
override fun compare(p0: String, p1: String) = comparator(p0, p1)
})
}
fun compare(s1: String, s2: String) = s1.compareTo(s2)
fun box(): String {
val l = ArrayList(Arrays.asList("d", "b", "c", "e", "a"))
sort(l, ::compare)
if (l != Arrays.asList("a", "b", "c", "d", "e")) return "Fail: $l"
return "OK"
}
@@ -1,11 +0,0 @@
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"
}
@@ -1,11 +0,0 @@
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"
}
@@ -1,6 +0,0 @@
fun foo() = "OK"
fun box(): String {
val x = ::foo
return x()
}
@@ -1,6 +0,0 @@
fun foo(x: String) = x
fun box(): String {
val x = ::foo
return x("OK")
}
@@ -1,11 +0,0 @@
var result = "Fail"
fun foo() {
result = "OK"
}
fun box(): String {
val x = ::foo
x()
return result
}
@@ -1,11 +0,0 @@
var result = "Fail"
fun foo(newResult: String) {
result = newResult
}
fun box(): String {
val x = ::foo
x("OK")
return result
}
@@ -1,11 +0,0 @@
interface T {
fun foo() = "OK"
}
class B : T {
inner class C {
fun bar() = (T::foo)(this@B)
}
}
fun box() = B().C().bar()
@@ -1,9 +0,0 @@
interface A {
fun foo(): String
}
class B : A {
override fun foo() = "OK"
}
fun box() = (A::foo)(B())
@@ -1,9 +0,0 @@
abstract class Base {
val result = "OK"
}
class Derived : Base()
fun box(): String {
return (Base::result).get(Derived())
}
@@ -1,24 +0,0 @@
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"
}
@@ -1,24 +0,0 @@
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()
}
@@ -1,11 +0,0 @@
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"
}
@@ -1,6 +0,0 @@
val Array<String>.firstElement: String get() = get(0)
fun box(): String {
val p = Array<String>::firstElement
return p.get(arrayOf("OK", "Fail"))
}
@@ -1,21 +0,0 @@
//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
}
@@ -1,31 +0,0 @@
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"
}
@@ -1,14 +0,0 @@
// 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"
}
@@ -1,13 +0,0 @@
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())
}
@@ -1,22 +0,0 @@
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()
}
@@ -1,9 +0,0 @@
fun box(): String {
class Local {
var result = "Fail"
}
val l = Local()
(Local::result).set(l, "OK")
return (Local::result).get(l)
}
@@ -1,9 +0,0 @@
open class Base {
open val foo = "Base"
}
class Derived : Base() {
override val foo = "OK"
}
fun box() = (Base::foo).get(Derived())
@@ -1,12 +0,0 @@
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")
}
@@ -1,9 +0,0 @@
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"
}
@@ -1,18 +0,0 @@
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"
}
@@ -1,16 +0,0 @@
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"
}
@@ -1,12 +0,0 @@
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"
}
@@ -1,10 +0,0 @@
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"
}
@@ -1,44 +0,0 @@
fun fn0() {}
fun fn1(x: Any) {}
inline fun asFailsWithCCE(operation: String, block: () -> Unit) {
try {
block()
}
catch (e: java.lang.ClassCastException) {
return
}
catch (e: Throwable) {
throw AssertionError("$operation: should throw ClassCastException, got $e")
}
throw AssertionError("$operation: should throw ClassCastException, no exception thrown")
}
inline fun asSucceeds(operation: String, block: () -> Unit) {
try {
block()
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
class MyFun: Function<Any>
fun box(): String {
val f0 = ::fn0 as Any
val f1 = ::fn1 as Any
val myFun = MyFun() as Any
asSucceeds("f0 as Function0<*>") { f0 as Function0<*> }
asFailsWithCCE("f0 as Function1<*, *>") { f0 as Function1<*, *> }
asFailsWithCCE("f1 as Function0<*>") { f1 as Function0<*> }
asSucceeds("f1 as Function1<*, *>") { f1 as Function1<*, *> }
asFailsWithCCE("myFun as Function0<*>") { myFun as Function0<*> }
asFailsWithCCE("myFun as Function1<*, *>") { myFun as Function1<*, *> }
return "OK"
}
@@ -1,36 +0,0 @@
fun fn0() {}
fun fn1(x: Any) {}
inline fun <reified T> reifiedAsSucceeds(x: Any, operation: String) {
try {
x as T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
inline fun <reified T> reifiedAsFailsWithCCE(x: Any, operation: String) {
try {
x as T
}
catch (e: java.lang.ClassCastException) {
return
}
catch (e: Throwable) {
throw AssertionError("$operation: should throw ClassCastException, got $e")
}
throw AssertionError("$operation: should fail with CCE, no exception thrown")
}
fun box(): String {
val f0 = ::fn0 as Any
val f1 = ::fn1 as Any
reifiedAsSucceeds<Function0<*>>(f0, "f0 as Function0<*>")
reifiedAsFailsWithCCE<Function1<*, *>>(f0, "f0 as Function1<*, *>")
reifiedAsFailsWithCCE<Function0<*>>(f1, "f1 as Function0<*>")
reifiedAsSucceeds<Function1<*, *>>(f1, "f1 as Function1<*, *>")
return "OK"
}
@@ -1,285 +0,0 @@
// This is a big, ugly, semi-auto generated test.
// Use corresponding 'Small' test for debug.
fun fn0() {}
fun fn1(x0: Any) {}
fun fn2(x0: Any, x1: Any) {}
fun fn3(x0: Any, x1: Any, x2: Any) {}
fun fn4(x0: Any, x1: Any, x2: Any, x3: Any) {}
fun fn5(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any) {}
fun fn6(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any) {}
fun fn7(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any) {}
fun fn8(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any) {}
fun fn9(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any) {}
fun fn10(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any) {}
fun fn11(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any) {}
fun fn12(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any) {}
fun fn13(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any) {}
fun fn14(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any) {}
fun fn15(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any) {}
fun fn16(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any) {}
fun fn17(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any) {}
fun fn18(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any) {}
fun fn19(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any) {}
fun fn20(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any) {}
fun fn21(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any) {}
fun fn22(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any, x21: Any) {}
val fns = arrayOf<Any>(::fn0, ::fn1, ::fn2, ::fn3, ::fn4, ::fn5, ::fn6, ::fn7, ::fn8, ::fn9,
::fn10, ::fn11, ::fn12, ::fn13, ::fn14, ::fn15, ::fn16, ::fn17, ::fn18, ::fn19,
::fn20, ::fn21, ::fn22)
inline fun <reified T> reifiedSafeAsReturnsNonNull(x: Any?, operation: String) {
val y = try {
x as? T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
if (y == null) {
throw AssertionError("$operation: should return non-null, got null")
}
}
inline fun <reified T> reifiedSafeAsReturnsNull(x: Any?, operation: String) {
val y = try {
x as? T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
if (y != null) {
throw AssertionError("$operation: should return null, got $y")
}
}
interface TestFnBase {
fun testGood(x: Any)
fun testBad(x: Any)
}
object TestFn0 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function0<*>>(
x, "x as? Function0<*>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function0<*>>(
x, "x as? Function0<*>")
}
object TestFn1 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function1<*, *>>(
x, "x as? Function1<*, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function1<*, *>>(
x, "x as? Function1<*, *>")
}
object TestFn2 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function2<*, *, *>>(
x, "x as? Function2<*, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function2<*, *, *>>(
x, "x as? Function2<*, *, *>")
}
object TestFn3 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function3<*, *, *, *>>(
x, "x as? Function3<*, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function3<*, *, *, *>>(
x, "x as? Function3<*, *, *, *>")
}
object TestFn4 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function4<*, *, *, *, *>>(
x, "x as? Function4<*, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function4<*, *, *, *, *>>(
x, "x as? Function4<*, *, *, *, *>")
}
object TestFn5 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function5<*, *, *, *, *, *>>(
x, "x as? Function5<*, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function5<*, *, *, *, *, *>>(
x, "x as? Function5<*, *, *, *, *, *>")
}
object TestFn6 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function6<*, *, *, *, *, *, *>>(
x, "x as? Function6<*, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function6<*, *, *, *, *, *, *>>(
x, "x as? Function6<*, *, *, *, *, *, *>")
}
object TestFn7 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function7<*, *, *, *, *, *, *, *>>(
x, "x as? Function7<*, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function7<*, *, *, *, *, *, *, *>>(
x, "x as? Function7<*, *, *, *, *, *, *, *>")
}
object TestFn8 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function8<*, *, *, *, *, *, *, *, *>>(
x, "x as? Function8<*, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function8<*, *, *, *, *, *, *, *, *>>(
x, "x as? Function8<*, *, *, *, *, *, *, *, *>")
}
object TestFn9 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function9<*, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function9<*, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function9<*, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function9<*, *, *, *, *, *, *, *, *, *>")
}
object TestFn10 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function10<*, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function10<*, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function10<*, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function10<*, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn11 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function11<*, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function11<*, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function11<*, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function11<*, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn12 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn13 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn14 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn15 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn16 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn17 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn18 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn19 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn20 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn21 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn22 : TestFnBase {
override fun testGood(x: Any) =
reifiedSafeAsReturnsNonNull<Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedSafeAsReturnsNull<Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as? Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
val tests = arrayOf<TestFnBase>(TestFn0, TestFn1, TestFn2, TestFn3, TestFn4, TestFn5, TestFn6, TestFn7, TestFn8, TestFn9,
TestFn10, TestFn11, TestFn12, TestFn13, TestFn14, TestFn15, TestFn16, TestFn17, TestFn18, TestFn19,
TestFn20, TestFn21, TestFn22)
fun box(): String {
for (fnI in 0 .. 22) {
for (testI in 0 .. 22) {
if (fnI == testI) {
tests[testI].testGood(fns[fnI])
}
else {
tests[testI].testBad(fns[fnI])
}
}
}
return "OK"
}
@@ -1,41 +0,0 @@
fun fn0() {}
fun fn1(x: Any) {}
inline fun <reified T> reifiedSafeAsReturnsNonNull(x: Any?, operation: String) {
val y = try {
x as? T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
if (y == null) {
throw AssertionError("$operation: should return non-null, got null")
}
}
inline fun <reified T> reifiedSafeAsReturnsNull(x: Any?, operation: String) {
val y = try {
x as? T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
if (y != null) {
throw AssertionError("$operation: should return null, got $y")
}
}
fun box(): String {
val f0 = ::fn0 as Any
val f1 = ::fn1 as Any
reifiedSafeAsReturnsNonNull<Function0<*>>(f0, "f0 as Function0<*>")
reifiedSafeAsReturnsNull<Function1<*, *>>(f0, "f0 as Function1<*, *>")
reifiedSafeAsReturnsNull<Function0<*>>(f1, "f1 as Function0<*>")
reifiedSafeAsReturnsNonNull<Function1<*, *>>(f1, "f1 as Function1<*, *>")
reifiedSafeAsReturnsNull<Function0<*>>(null, "null as Function0<*>")
reifiedSafeAsReturnsNull<Function1<*, *>>(null, "null as Function1<*, *>")
return "OK"
}
-109
View File
@@ -1,109 +0,0 @@
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"
}
@@ -1,26 +0,0 @@
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)
System.out?.println(i)
a[i++]// = mInt(1)
System.out?.println(i)
a[i++] = mInt(1)
System.out?.println(i)
for (i in 0..9)
System.out?.println("ar: ${a[mInt(i)]}")
return "OK"
}
@@ -1,10 +0,0 @@
data class A(val x: Array<Int>, val y: IntArray)
fun foo(x: Array<Int>, y: IntArray) = A(x, y)
fun box(): String {
val a = Array<Int>(0, {0})
val b = IntArray(0)
val (x, y) = foo(a, b)
return if (a == x && b == y) "OK" else "Fail"
}

Some files were not shown because too many files have changed in this diff Show More