tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fun <T : Number?> foo(t: T) {
|
||||
t?.toInt()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo<Int?>(null)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//KT-1572 Frontend doesn't mark all vars included in closure as refs.
|
||||
|
||||
class A(val t : Int) {}
|
||||
|
||||
fun testKt1572() : Boolean {
|
||||
var a = A(0)
|
||||
var b = A(3)
|
||||
val changer = {a = b}
|
||||
b = A(10) // this change has no effect on changer
|
||||
changer()
|
||||
return (a.t == 10)
|
||||
}
|
||||
|
||||
fun testPrimitives() : Boolean {
|
||||
var a = 0
|
||||
var b = 3
|
||||
val changer = {a = b}
|
||||
b = 10
|
||||
changer()
|
||||
return (a == 10)
|
||||
}
|
||||
|
||||
fun box() = if (testKt1572() && testPrimitives()) "OK" else "fail"
|
||||
@@ -0,0 +1,13 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
class A() {
|
||||
fun foo() {
|
||||
System.out?.println(1)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a : A = A()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
fun foo() {
|
||||
val l = ArrayList<Int>(2)
|
||||
l.add(1)
|
||||
|
||||
for (el in l) {}
|
||||
|
||||
//verify error "Expecting to find integer on stack"
|
||||
val iterator = l.iterator()
|
||||
|
||||
//another verify error "Mismatched stack types"
|
||||
while (iterator?.hasNext() ?: false) {
|
||||
val i = iterator?.next()
|
||||
}
|
||||
|
||||
//the same
|
||||
if (iterator != null) {
|
||||
while (iterator.hasNext()) {
|
||||
val i = iterator?.next()
|
||||
}
|
||||
}
|
||||
|
||||
//this way it works
|
||||
if (iterator != null) {
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next() //because of the bug KT-244 i can't write "val i = iterator.next()"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
fun t1() : Boolean {
|
||||
val s1 : String? = "sff"
|
||||
val s2 : String? = null
|
||||
return s1?.length == 3 && s2?.length == null
|
||||
}
|
||||
|
||||
fun t2() : Boolean {
|
||||
val c1: C? = C(1)
|
||||
val c2: C? = null
|
||||
return c1?.x == 1 && c2?.x == null
|
||||
}
|
||||
|
||||
fun t3() {
|
||||
val d: D = D("s")
|
||||
val x = d?.s
|
||||
if (!(d?.s == "s")) throw AssertionError()
|
||||
}
|
||||
|
||||
fun t4() {
|
||||
val e: E? = E()
|
||||
if (!(e?.bar() == e)) throw AssertionError()
|
||||
val x = e?.foo()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(!t1 ()) return "fail"
|
||||
if(!t2 ()) return "fail"
|
||||
t3()
|
||||
t4()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
class C(val x: Int)
|
||||
class D(val s: String)
|
||||
class E() {
|
||||
fun foo() = 1
|
||||
fun bar() = this
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun f(b : Int.(Int)->Int) = 1?.b(1)
|
||||
|
||||
fun box(): String {
|
||||
val x = f { this + it }
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
class Test {
|
||||
val Long.foo: Long
|
||||
get() = this + 1
|
||||
|
||||
val Int.foo: Int
|
||||
get() = this + 1
|
||||
|
||||
fun testLong(): Long? {
|
||||
var s: Long? = 10;
|
||||
return s?.foo
|
||||
}
|
||||
|
||||
fun testInt(): Int? {
|
||||
var s: Int? = 11;
|
||||
return s?.foo
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = Test()
|
||||
|
||||
if (s.testLong() != 11.toLong()) return "fail 1"
|
||||
|
||||
if (s.testInt() != 12) return "fail 1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun Int.foo() = 239
|
||||
fun Long.bar() = 239.toLong()
|
||||
|
||||
fun box(): String {
|
||||
42?.foo()
|
||||
42.toLong()?.bar()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun f(b : Long.(Long)->Long) = 1L?.b(2L)
|
||||
|
||||
fun box(): String {
|
||||
val x = f { this + it }
|
||||
return if (x == 3L) "OK" else "fail $x"
|
||||
}
|
||||
Reference in New Issue
Block a user