tests: Update box tests (1050294:id)

This commit is contained in:
Ilya Matveev
2017-04-24 17:17:41 +07:00
committed by ilmat192
parent 569ceff5f9
commit 8df15dca5a
96 changed files with 1165 additions and 145 deletions
@@ -0,0 +1,17 @@
// IGNORE_BACKEND: JVM, JS, NATIVE
// Here we check that there is compilation error, so ignore_backend directive is actual
@Target(AnnotationTarget.FIELD, AnnotationTarget.CLASS)
annotation class Anno
class UnresolvedArgument(@Anno(BLA) val s: Int)
class WithoutArguments(@Deprecated val s: Int)
fun box(): String {
UnresolvedArgument(3)
WithoutArguments(0)
return "OK"
}
@@ -1,6 +1,3 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
//test [], get and iterator calls
fun test(createIntNotLong: Boolean): String {
val a = if (createIntNotLong) IntArray(5) else LongArray(5)
@@ -25,5 +22,8 @@ fun test(createIntNotLong: Boolean): String {
}
fun box(): String {
// Only run this test if primitive array `is` checks work (KT-17137)
if ((intArrayOf() as Any) is Array<*>) return "OK"
return test(true) + test(false)
}
@@ -1,6 +1,3 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
fun box(): String {
val a = ByteArray(5)
val x = a.iterator()
@@ -1,6 +1,3 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
fun box(): String {
val a = LongArray(5)
val x = a.iterator()
@@ -0,0 +1,17 @@
//WITH_RUNTIME
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: NATIVE
object A {
@JvmStatic fun main(args: Array<String>) {
val b = arrayOf(arrayOf(""))
object {
val c = b[0]
}
}
}
fun box(): String {
A.main(emptyArray())
return "OK"
}
+3 -2
View File
@@ -1,6 +1,4 @@
//KT-2997 Automatically cast error (Array)
// IGNORE_BACKEND: JS
// Unmute when JS implements primitive arrays via TypeArray
fun foo(a: Any): Int {
if (a is IntArray) {
@@ -55,6 +53,9 @@ fun foo(a: Any): Int {
}
fun box(): String {
// Only run this test if primitive array `is` checks work (KT-17137)
if ((intArrayOf() as Any) is Array<*>) return "OK"
val iA = IntArray(1)
if (foo(iA) != 1) return "fail int[]"
val sA = ShortArray(1)
@@ -21,6 +21,9 @@ fun test(b: Boolean): String {
}
fun box(): String {
// Only run this test if primitive array `is` checks work (KT-17137)
if ((intArrayOf() as Any) is Array<*>) return "OK"
if (test(true) != "OK") return "fail 1: ${test(true)}"
if (test(false) != "OK") return "fail 1: ${test(false)}"
@@ -0,0 +1,8 @@
// IGNORE_BACKEND: JS
fun equals1(a: Double, b: Double) = a.equals(b)
fun box(): String {
if ((-0.0).equals(0.0)) return "fail 0"
return "OK"
}
@@ -0,0 +1,5 @@
fun box() =
if (getAndCheck({ 42 }, { 42 })) "OK" else "fail"
inline fun <T> getAndCheck(getFirst: () -> T, getSecond: () -> T) =
getFirst() == getSecond()
@@ -1,53 +0,0 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// FULL_JDK
// WITH_RUNTIME
interface ImmutableCollection<out E> : Collection<E> {
fun add(element: @UnsafeVariance E): ImmutableCollection<E>
fun addAll(elements: Collection<@UnsafeVariance E>): ImmutableCollection<E>
fun remove(element: @UnsafeVariance E): ImmutableCollection<E>
}
class ImmutableCollectionmpl<E> : ImmutableCollection<E> {
override val size: Int
get() = throw UnsupportedOperationException()
override fun contains(element: E): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun containsAll(elements: Collection<E>): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun isEmpty(): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun iterator(): Iterator<E> {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun add(element: E): ImmutableCollection<E> = this
override fun addAll(elements: Collection<E>): ImmutableCollection<E> = this
override fun remove(element: E): ImmutableCollection<E> = this
}
fun box(): String {
val c = ImmutableCollectionmpl<String>()
if (c.remove("") !== c) return "fail 1"
if (c.add("") !== c) return "fail 2"
if (c.addAll(java.util.ArrayList()) !== c) return "fail 3"
val method = c.javaClass.methods.single { it.name == "remove" && it.returnType == Boolean::class.javaPrimitiveType }
try {
method.invoke(c, "")
return "fail 4"
} catch (e: java.lang.reflect.InvocationTargetException) {
if (e.cause!!.message != "Operation is not supported for read-only collection") return "fail 5: ${e.cause!!.message}"
}
return "OK"
}
@@ -0,0 +1,14 @@
// IGNORE_BACKEND: NATIVE
class Generic<P : Any>(val p: P)
class Host {
fun t() {}
val v = "OK"
}
fun box(): String {
Generic(Host()).p::class
(Generic(Host()).p::t)()
return (Generic(Host()).p::v)()
}
@@ -0,0 +1,15 @@
class B
fun B.magic() {
}
fun boom(a: Any) {
when (a) {
is B -> run(a::magic)
}
}
fun box(): String {
boom(B())
return "OK"
}
@@ -1,5 +1,6 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
@@ -0,0 +1,13 @@
// IGNORE_BACKEND: JS, NATIVE
fun box(): String {
fun bar() {}
fun baz() {}
if (!::bar.equals(::bar)) return "Fail 1"
if (::bar.hashCode() != ::bar.hashCode()) return "Fail 2"
if (::bar == ::baz) return "Fail 3"
return "OK"
}
@@ -0,0 +1,9 @@
inline fun runCrossInline(crossinline f: () -> Unit) {
f()
}
fun box(): String {
var x = ""
runCrossInline { x = "OK" }
return x
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun box(): String {
var x = ""
run { x = "OK" }
return x
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
fun box(): String {
var x = ""
run {
x += "O"
x += "K"
}
return x
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
fun box(): String {
var x = 0
run { x++ }
run { ++x }
return if (x == 2) "OK" else "Fail: $x"
}
@@ -0,0 +1,18 @@
// WITH_RUNTIME
class Host(var value: String) {
operator fun get(i: Int, j: Int, k: Int) = value
operator fun set(i: Int, j: Int, k: Int, newValue: String) {
value = newValue
}
}
fun box(): String {
var x = Host("")
run {
x[0, 0, 0] += "O"
x[0, 0, 0] += "K"
}
return x.value
}
@@ -0,0 +1,26 @@
// WITH_RUNTIME
fun box(): String {
var xl = 0L // Long, size 2
var xi = 0 // Int, size 1
var xd = 0.0 // Double, size 2
run {
xl++
xd += 1.0
xi++
}
run {
run {
xl++
xd += 1.0
xi++
}
}
if (xi != 2) return "fail: xi=$xi"
if (xl != 2L) return "fail: xl=$xl"
if (xd != 2.0) return "fail: xd=$xd"
return "OK"
}
@@ -0,0 +1,26 @@
inline fun inlineCall(action: () -> Unit) {
action()
}
fun test() {
var width = 1
inlineCall {
width += width
}
}
fun test2() {
var width = 1L
val newValue = 1;
val newValue2 = "123";
val newValue3 = 2.0;
inlineCall {
width += width
}
}
fun box(): String {
test()
test2()
return "OK"
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
fun box(): String {
run {
run {
var x = 0
run { ++x }
if (x == 0) return "fail"
}
run {
var x = 0
run { x++ }
if (x == 0) return "fail"
}
}
return "OK"
}
@@ -0,0 +1,41 @@
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
class Controller {
var result = ""
suspend fun <T> suspendWithResult(value: T): T = suspendCoroutineOrReturn { c ->
c.resume(value)
COROUTINE_SUSPENDED
}
}
fun builder(c: suspend Controller.() -> Unit): String {
val controller = Controller()
c.startCoroutine(controller, EmptyContinuation)
return controller.result
}
fun box(): String {
val value = builder {
var r = ""
for (x in listOf("O", "$", "K")) {
if (x == "$") continue
run {
r += suspendWithResult(x)
}
}
run {
r += "."
}
result = r
}
if (value != "OK.") return "fail: suspend in for body: $value"
return "OK"
}
@@ -0,0 +1,45 @@
// LANGUAGE_VERSION: 1.2
// WITH_REFLECT
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: NATIVE
import java.util.Arrays
import kotlin.reflect.KClass
import kotlin.reflect.KFunction0
inline fun <reified T> test(kFunction: KFunction0<Unit>, test: T.() -> Unit) {
val annotation = kFunction.annotations.single() as T
annotation.test()
}
fun check(b: Boolean, message: String) {
if (!b) throw RuntimeException(message)
}
annotation class Foo(val a: FloatArray = [], val b: Array<String> = [], val c: Array<KClass<*>> = [])
@Foo(a = [1f, 2f, 1 / 0f])
fun test1() {}
@Foo(b = ["Hello", ", ", "Kot" + "lin"])
fun test2() {}
@Foo(c = [Int::class, Array<Short>::class, Foo::class])
fun test3() {}
fun box(): String {
test<Foo>(::test1) {
check(a.contentEquals(floatArrayOf(1f, 2f, Float.POSITIVE_INFINITY)), "Fail 1: ${a.joinToString()}")
}
test<Foo>(::test2) {
check(b.contentEquals(arrayOf("Hello", ", ", "Kotlin")), "Fail 2: ${b.joinToString()}")
}
test<Foo>(::test3) {
check(c.contentEquals(arrayOf(Int::class, Array<Short>::class, Foo::class)), "Fail 3: ${c.joinToString()}")
}
return "OK"
}
@@ -0,0 +1,38 @@
// LANGUAGE_VERSION: 1.2
// WITH_REFLECT
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: NATIVE
import java.util.Arrays
import kotlin.reflect.KFunction0
inline fun <reified T> test(kFunction: KFunction0<Unit>, test: T.() -> Unit) {
val annotation = kFunction.annotations.single() as T
annotation.test()
}
fun check(b: Boolean, message: String) {
if (!b) throw RuntimeException(message)
}
annotation class Foo(val a: IntArray = [], val b: Array<String> = [])
const val ONE_INT = 1
const val ONE_FLOAT = 1f
const val HELLO = "hello"
const val C_CHAR = 'c'
@Foo(
a = [ONE_INT, ONE_INT + ONE_FLOAT.toInt(), ONE_INT + 10, (ONE_INT % 1.0).toInt()],
b = [HELLO, HELLO + C_CHAR, HELLO + ", Kotlin", C_CHAR.toString() + C_CHAR])
fun test1() {}
fun box(): String {
test<Foo>(::test1) {
check(a.contentEquals(intArrayOf(1, 2, 11, 0)), "Fail 1: ${a.joinToString()}")
check(b.contentEquals(arrayOf("hello", "helloc", "hello, Kotlin", "cc")), "Fail 2: ${b.joinToString()}")
}
return "OK"
}
@@ -0,0 +1,40 @@
// LANGUAGE_VERSION: 1.2
// WITH_REFLECT
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: NATIVE
import java.util.Arrays
import kotlin.reflect.KClass
import kotlin.reflect.KFunction0
inline fun <reified T> test(kFunction: KFunction0<Unit>, test: T.() -> Unit) {
val annotation = kFunction.annotations.single() as T
annotation.test()
}
fun check(b: Boolean, message: String) {
if (!b) throw RuntimeException(message)
}
annotation class Foo(vararg val a: String = ["a", "b"])
annotation class Bar(vararg val a: KClass<*> = [Int::class])
@Foo(*["/"])
fun test1() {}
@Bar(*[Long::class, String::class])
fun test2() {}
fun box(): String {
test<Foo>(::test1) {
check(a.contentEquals(arrayOf("/")), "Fail 1: ${a.joinToString()}")
}
test<Bar>(::test2) {
check(a.contentEquals(arrayOf(Long::class, String::class)), "Fail 2: ${a.joinToString()}")
}
return "OK"
}
@@ -0,0 +1,40 @@
// LANGUAGE_VERSION: 1.2
// WITH_REFLECT
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: NATIVE
import java.util.Arrays
import kotlin.reflect.KClass
import kotlin.reflect.KFunction0
inline fun <reified T> test(kFunction: KFunction0<Unit>, test: T.() -> String): String {
val annotation = kFunction.annotations.single() as T
return annotation.test()
}
fun check(b: Boolean, message: String) {
if (!b) throw RuntimeException(message)
}
annotation class Foo(
val a: IntArray = [],
val b: IntArray = [1, 2, 3],
val c: Array<String> = ["/"],
val d: Array<KClass<*>> = [Int::class, Array<Int>::class],
val e: DoubleArray = [1.0]
)
@Foo
fun withAnn() {}
fun box(): String {
return test<Foo>(::withAnn) {
check(a.contentEquals(intArrayOf()), "Fail 1: ${a.joinToString()}")
check(b.contentEquals(intArrayOf(1, 2, 3)), "Fail 2: ${b.joinToString()}")
check(c.contentEquals(arrayOf("/")), "Fail 3: ${c.joinToString()}")
check(d.contentEquals(arrayOf(Int::class, Array<Int>::class)), "Fail 4: ${d.joinToString()}")
check(e.contentEquals(doubleArrayOf(1.0)), "Fail 5: ${e.joinToString()}")
"OK"
}
}
@@ -1,6 +1,6 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: NATIVE
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
import kotlin.test.assertEquals
@@ -1,6 +1,6 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: NATIVE
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
import kotlin.test.assertEquals
@@ -0,0 +1,78 @@
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
fun box(): String {
async {
O.foo()
O.foo("second")
}
while (!finished) {
result += "--;"
proceed()
}
finished = false
asyncSuspend {
O.foo()
O.foo("second")
}
while (!finished) {
result += "--;"
proceed()
}
val expected = "before(first);--;after(first);before(second);--;after(second);--;done;"
if (result != expected + expected) return "fail: $result"
return "OK"
}
interface I {
suspend fun foo(x: String = "first")
}
object O : I {
override suspend fun foo(x: String) {
result += "before($x);"
sleep()
result += "after($x);"
}
}
suspend fun sleep(): Unit = suspendCoroutine { c ->
proceed = { c.resume(Unit) }
}
fun async(f: suspend () -> Unit) {
f.startCoroutine(object : Continuation<Unit> {
override fun resume(x: Unit) {
proceed = {
result += "done;"
finished = true
}
}
override fun resumeWithException(x: Throwable) {}
override val context = EmptyCoroutineContext
})
}
fun asyncSuspend(f: suspend () -> Unit) {
val coroutine = f.createCoroutine(object : Continuation<Unit> {
override fun resume(x: Unit) {
proceed = {
result += "done;"
finished = true
}
}
override fun resumeWithException(x: Throwable) {}
override val context = EmptyCoroutineContext
})
coroutine.resume(Unit)
}
var result = ""
var proceed: () -> Unit = { }
var finished = false
@@ -0,0 +1,42 @@
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
fun box(): String {
var result = 0
builder {
result = factorial(4)
}
while (postponed != null) {
postponed!!()
}
if (result != 24) return "fail1: $result"
if (log != "1;1;2;6;24;") return "fail2: $log"
return "OK"
}
suspend fun factorial(a: Int): Int = if (a > 0) suspendHere(factorial(a - 1) * a) else suspendHere(1)
suspend fun suspendHere(value: Int): Int = suspendCoroutineOrReturn { x ->
postponed = {
log += "$value;"
x.resume(value)
}
COROUTINE_SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(handleResultContinuation {
postponed = null
})
}
var postponed: (() -> Unit)? = { }
var log = ""
@@ -0,0 +1,48 @@
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn
import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED
fun box(): String {
async {
log += "1;"
wait()
log += "2;"
}
while (postponed != null) {
log += "suspended;"
postponed!!()
}
if (log != "1;wait2;suspended;wait;suspended;2;") return "fail: $log"
return "OK"
}
fun async(f: suspend () -> Unit) {
f.startCoroutine(handleResultContinuation {
postponed = null
})
}
suspend fun wait(): Unit {
wait2()
log += "wait;"
return suspendCoroutineOrReturn { c ->
postponed = { c.resume(Unit) }
COROUTINE_SUSPENDED
}
}
suspend fun wait2(): Unit = suspendCoroutineOrReturn { c ->
log += "wait2;"
postponed = { c.resume(Unit) }
COROUTINE_SUSPENDED
}
var postponed: (() -> Unit)? = { }
var log = ""
@@ -1,4 +1,4 @@
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
@@ -0,0 +1,53 @@
// IGNORE_BACKEND: NATIVE
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
fun box(): String {
async {
val a = foo(23)
log(a)
val b = foo(42)
log(b)
}
while (!finished) {
log("--")
proceed()
}
if (result != "suspend:23;--;23;suspend:42;--;42;--;done;") return "fail: $result"
return "OK"
}
var result = ""
fun log(message: Any) {
result += "$message;"
}
var proceed: () -> Unit = { }
var finished = false
suspend fun bar(x: Int): Int = suspendCoroutine { c ->
log("suspend:$x")
proceed = { c.resume(x) }
}
inline suspend fun foo(x: Int) = bar(x)
fun async(a: suspend () -> Unit) {
a.startCoroutine(object : Continuation<Unit> {
override fun resume(value: Unit) {
proceed = {
log("done")
finished = true
}
}
override fun resumeWithException(e: Throwable) {
}
override val context = EmptyCoroutineContext
})
}
@@ -0,0 +1,9 @@
data class A(val o: String, val k: String) {
constructor() : this("O", "k")
}
fun box(): String {
val a = A().copy(k = "K")
return a.o + a.k
}
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: NATIVE
// No kotlin-reflect.jar in this test
// WITH_RUNTIME
@@ -0,0 +1,46 @@
var result = ""
enum class E(a: String) {
X("x"),
Y("y");
init {
result += "E.init($a);"
}
companion object {
init {
result += "E.companion.init;"
val value = E.values()[0].name
result += "$value;"
}
}
}
enum class F(a: String) {
X("x"),
Y("y");
init {
result += "F.init($a);"
}
companion object {
init {
result += "F.companion.init;"
}
fun foo() {
result += "F.foo();$X;"
}
}
}
fun box(): String {
val y = E.Y
result += "${y.name};"
F.foo()
if (result != "E.init(x);E.init(y);E.companion.init;X;Y;F.init(x);F.init(y);F.companion.init;F.foo();X;") return "fail: $result"
return "OK"
}
@@ -2,21 +2,16 @@
// IGNORE_BACKEND: JS, NATIVE
// FULL_JDK
// WITH_RUNTIME
//This front-end problem test added to box ones only cause of FULL_JDK support
import org.w3c.dom.Element
import org.xml.sax.InputSource
import javax.xml.parsers.DocumentBuilderFactory
import java.io.StringReader
class MyElement(e: Element): Element by e {
fun bar() = "OK"
}
fun box() : String {
val factory = DocumentBuilderFactory.newInstance()!!;
val builder = factory.newDocumentBuilder()!!;
val source = InputSource(StringReader("<OK></OK>"));
val doc = builder.parse(source)!!;
val myElement = MyElement(doc.getDocumentElement()!!)
return myElement.getTagName()!!
val touch = MyElement::class.java
return "OK"
}
@@ -2,6 +2,9 @@
fun box(): String {
val plusZero: Double? = 0.0
val minusZero: Double = -0.0
useBoxed(plusZero)
if (plusZero?.equals(minusZero) ?: null!!) {
return "fail 1"
}
@@ -11,4 +14,6 @@ fun box(): String {
}
return "OK"
}
}
fun useBoxed(a: Any?) {}
@@ -0,0 +1,22 @@
fun test1(): Boolean {
test1@ for(i in 1..2) {
continue@test1
return false
}
return true
}
fun test2(): Boolean {
test2@ while (true) {
break@test2
}
return true
}
fun box(): String {
if (!test1()) return "fail test1"
if (!test2()) return "fail test2"
return "OK"
}
@@ -0,0 +1,24 @@
fun test(x: Int): Int {
x myMap {
return@myMap
}
return 0
}
fun myMap(x: Int): Int {
x myMap {
return@myMap
}
return 0
}
infix fun Int.myMap(x: () -> Unit) {}
fun box(): String {
test(0)
myMap(0)
return "OK"
}
@@ -0,0 +1,11 @@
fun foo(): String {
fun bar(x: String, y: String = x): String {
return y
}
return bar("OK")
}
fun box(): String {
return foo()
}
@@ -10,5 +10,5 @@ fun box() : String {
val (`_`, c) = A()
return if (a == 1 && b == 2 && _ == 1 && c == 2) "OK" else "fail"
return if (a == 1 && b == 2 && `_` == 1 && c == 2) "OK" else "fail"
}
@@ -31,7 +31,7 @@ fun doTest(): String {
}
for ((_, `_`) in C(2)..C(4)) {
s += "$_;"
s += "$`_`;"
}
return s
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: Baz.java
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KOTLIN_CONFIGURATION_FLAGS: +JVM.INHERIT_MULTIFILE_PARTS
// FILE: box.kt
@@ -0,0 +1,13 @@
interface ClassData
fun f() = object : ClassData {
val someInt: Int
get() {
return 5
}
}
fun box(): String{
f()
return "OK"
}
@@ -0,0 +1,4 @@
inline fun <reified T> isNullable() = null is T
fun box(): String =
if (isNullable<String?>()) "OK" else "Fail"
@@ -0,0 +1,12 @@
var flag = false
inline fun foo(c: String? = null) {
if (c != null) {
flag = true
}
}
fun box(): String {
foo()
return if (flag) "fail" else "OK"
}
@@ -0,0 +1,22 @@
interface IFoo {
fun foo(): String
}
interface IBar
private fun createAnonObject() =
object : IFoo, IBar {
override fun foo() = "foo"
fun qux(): String = "qux"
}
fun useAnonObject() {
createAnonObject().foo()
createAnonObject().qux()
}
fun box(): String {
if (createAnonObject().foo() != "foo") return "fail 1"
if (createAnonObject().qux() != "qux") return "fail 2"
return "OK"
}
@@ -0,0 +1,40 @@
package test
import test.C.E1
import test.A.B.*
import test.Obj.CInObj.Tt
import test.Obj.foo
private enum class C {
E1
}
class A {
private class B {
object C
class D
}
fun test() {
C
D()
}
}
private object Obj {
private class CInObj {
class Tt
}
fun foo() {
Tt()
}
}
fun box(): String {
E1
A().test()
foo()
return "OK"
}
@@ -2,14 +2,18 @@
//WITH_REFLECT
class A {
@PublishedApi
internal fun published() = "OK"
internal fun published() = "O"
inline fun test() = published()
@PublishedApi
internal var publishedProp = "K"
inline fun test() = published() + publishedProp
}
fun box() : String {
val clazz = A::class.java
if (clazz.getDeclaredMethod("published") == null) return "fail"
return "OK"
if (clazz.getDeclaredMethod("published") == null) return "fail 1"
if (clazz.getDeclaredMethod("getPublishedProp") == null) return "fail 2"
if (clazz.getDeclaredMethod("setPublishedProp", String::class.java) == null) return "fail 3"
return A().test()
}
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -13,6 +13,9 @@ fun test(x: Any): Int {
}
fun box(): String {
// Only run this test if primitive array `is` checks work (KT-17137)
if ((intArrayOf() as Any) is Array<*>) return "OK"
assertEquals(123, test(intArrayOf(0, 0, 0, 0)))
return "OK"
}
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -1,5 +1,8 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: JS
// TODO: muted automatically, investigate should it be ran for NATIVE or not
// IGNORE_BACKEND: NATIVE
// Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
// WITH_RUNTIME
@@ -25,8 +25,10 @@ fun box(): String {
// Java class without nested classes
assertEquals(emptyList<String>(), nestedNames(Error::class))
// Java interface with nested classes
assertEquals(listOf("Entry"), nestedNames(java.util.Map::class))
// Java class with nested classes
assertEquals(listOf("State", "UncaughtExceptionHandler"), nestedNames(Thread::class))
assertEquals(listOf("SimpleEntry", "SimpleImmutableEntry"), nestedNames(java.util.AbstractMap::class))
// Built-ins
assertEquals(emptyList<String>(), nestedNames(Array<Any>::class))
@@ -1,22 +0,0 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE
// WITH_REFLECT
// FILE: J.java
public class J {
void foo(String s, int i) {}
static void bar(J j) {}
}
// FILE: K.kt
import kotlin.test.assertEquals
fun box(): String {
assertEquals(listOf(null, null, null), J::foo.parameters.map { it.name })
assertEquals(listOf(null), J::bar.parameters.map { it.name })
return "OK"
}
@@ -5,6 +5,9 @@
// FULL_JDK
// See KT-11258 Incorrect resolution sequence for Java field
// TODO: enable this test on JVM, see KT-16616
// IGNORE_BACKEND_WITHOUT_CHECK: JVM
import java.util.*
fun box(): String {
@@ -16,10 +16,10 @@ open class TypeLiteral<T> {
inline fun <reified T> typeLiteral(): TypeLiteral<T> = object : TypeLiteral<T>() {}
fun box(): String {
assertEquals("class java.lang.String", typeLiteral<String>().type.toString())
assertEquals("java.lang.String", (typeLiteral<String>().type as Class<*>).canonicalName)
assertEquals("java.util.List<?>", typeLiteral<List<*>>().type.toString())
assertEquals("java.lang.String[]", typeLiteral<Array<String>>().type.toString())
assertEquals("java.lang.Integer[]", typeLiteral<Array<Int>>().type.toString())
assertEquals("java.lang.String[][]", typeLiteral<Array<Array<String>>>().type.toString())
assertEquals("java.lang.String[]", (typeLiteral<Array<String>>().type as Class<*>).canonicalName)
assertEquals("java.lang.Integer[]", (typeLiteral<Array<Int>>().type as Class<*>).canonicalName)
assertEquals("java.lang.String[][]", (typeLiteral<Array<Array<String>>>().type as Class<*>).canonicalName)
return "OK"
}
}
@@ -5,8 +5,8 @@ package test
fun testProperLineNumberAfterInline(): String {
var exceptionCount = 0;
try {
checkEquals(test(),
"12")
fail(inlineFun(),
"12")
}
catch(e: AssertionError) {
val entry = (e as java.lang.Throwable).getStackTrace()!!.get(1)
@@ -18,8 +18,8 @@ fun testProperLineNumberAfterInline(): String {
}
try {
checkEquals("12",
test())
fail("12",
inlineFun())
}
catch(e: AssertionError) {
val entry = e.stackTrace!![1]
@@ -36,13 +36,13 @@ fun testProperLineNumberAfterInline(): String {
fun testProperLineForOtherParameters(): String {
var exceptionCount = 0;
try {
checkEquals(test(),
fail())
fail(inlineFun(),
fail())
}
catch(e: AssertionError) {
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("simpleCallWithParams.kt:39" != actual) {
if ("simpleCallWithParams.kt:40" != actual) {
return "fail 3: ${actual}"
}
exceptionCount++
@@ -50,8 +50,8 @@ fun testProperLineForOtherParameters(): String {
}
try {
checkEquals(fail(),
test())
fail(fail(),
inlineFun())
}
catch(e: AssertionError) {
val entry = e.stackTrace!![1]
@@ -63,7 +63,7 @@ fun testProperLineForOtherParameters(): String {
}
try {
checkEquals(fail(), test())
fail(fail(), inlineFun())
}
catch(e: AssertionError) {
val entry = e.stackTrace!![1]
@@ -75,7 +75,7 @@ fun testProperLineForOtherParameters(): String {
}
try {
checkEquals(fail(), test())
fail(fail(), inlineFun())
}
catch(e: AssertionError) {
val entry = e.stackTrace!![1]
@@ -97,11 +97,11 @@ fun box(): String {
return testProperLineForOtherParameters()
}
public fun checkEquals(p1: String, p2: String) {
public fun fail(p1: String, p2: String) {
throw AssertionError("fail")
}
inline fun test(): String {
inline fun inlineFun(): String {
return "123"
}
@@ -1,5 +1,6 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// IGNORE_LIGHT_ANALYSIS
// FILE: SingletonCollection.kt
package test
@@ -0,0 +1,54 @@
// MODULE: lib
// FILE: lib.kt
package utils
inline fun foo(a: Int) {
bar(a)
}
inline fun bar(a: Int) {
try {
if (a > 0) throw Exception()
log("foo($a) #1")
}
catch (e: Exception) {
myRun {
log("foo($a) #2")
if (a > 1) return
log("foo($a) #3")
}
}
log("foo($a) #4")
}
var LOG: String = ""
fun log(s: String): String {
LOG += s + ";"
return LOG
}
inline fun myRun(f: () -> Unit) = f()
// MODULE: main(lib)
// FILE: main.kt
import utils.*
fun box(): String {
foo(0)
if (LOG != "foo(0) #1;foo(0) #4;") return "fail1: $LOG"
LOG = ""
foo(1)
if (LOG != "foo(1) #2;foo(1) #3;foo(1) #4;") return "fail2: $LOG"
LOG = ""
foo(2)
if (LOG != "foo(2) #2;") return "fail3: $LOG"
LOG = ""
return "OK"
}
@@ -0,0 +1,51 @@
// MODULE: lib
// FILE: lib.kt
package utils
inline fun foo(a: Int) {
try {
if (a > 0) throw Exception()
log("foo($a)")
}
catch (e: Exception) {
bar(a)
}
}
inline fun bar(a: Int) {
myRun {
log("bar($a) #1")
if (a == 2) return
log("bar($a) #2")
}
}
var LOG: String = ""
fun log(s: String): String {
LOG += s + ";"
return LOG
}
inline fun myRun(f: () -> Unit) = f()
// MODULE: main(lib)
// FILE: main.kt
import utils.*
fun box(): String {
foo(0)
if (LOG != "foo(0);") return "fail1: $LOG"
LOG = ""
foo(1)
if (LOG != "bar(1) #1;bar(1) #2;") return "fail2: $LOG"
LOG = ""
foo(2)
if (LOG != "bar(2) #1;") return "fail3: $LOG"
return "OK"
}
@@ -0,0 +1,27 @@
// FILE: 1.kt
// FULL_JDK
// WITH_REFLECT
package test
import kotlin.properties.Delegates
import kotlin.properties.ReadWriteProperty
var result = "fail"
inline fun <reified T : Any> crashMe(): ReadWriteProperty<Any?, Unit> {
return Delegates.observable(Unit, { a, b, c -> result = T::class.java.simpleName })
}
// FILE: 2.kt
import test.*
class OK {
var value by crashMe<OK>()
}
fun box(): String {
OK().value = Unit
return result
}
@@ -0,0 +1,36 @@
// FILE: 1.kt
// FULL_JDK
// WITH_REFLECT
package test
import kotlin.properties.Delegates
import kotlin.properties.ReadWriteProperty
import kotlin.properties.ObservableProperty
import kotlin.reflect.KProperty
var result = "fail"
public inline fun <reified T> myObservable(initialValue: T, crossinline onChange: (property: KProperty<*>, oldValue: T, newValue: T) -> Unit):
ReadWriteProperty<Any?, T> = object : ObservableProperty<T>(initialValue) {
override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) = onChange(property, oldValue, newValue)
}
//samely named reified parameter (T) as in myObservable
inline fun <reified T : Any> crashMe(): ReadWriteProperty<Any?, Unit> {
return myObservable(Unit, { a, b, c -> result = T::class.java.simpleName })
}
// FILE: 2.kt
import test.*
class OK {
var value by crashMe<OK>()
}
fun box(): String {
OK().value = Unit
return result
}
+1 -1
View File
@@ -20,6 +20,6 @@ minMacOsVersion = 10.11
remoteRoot=konan_tests
#kotlinCompilerModule=org.jetbrains.kotlin:kotlin-compiler:1.1-SNAPSHOT
# Download artifacts of https://teamcity.jetbrains.com/viewType.html?buildTypeId=bt345
testDataVersion=1009012:id
testDataVersion=1050294:id
kotlinCompilerModule=org.jetbrains.kotlin:kotlin-compiler:1.1-20170424.172927-491
konanVersion=0.1