[Tests] Migrate backend-independent tests from native to compiler/testData.

^KT-65979
This commit is contained in:
Vladimir Sukharev
2024-02-25 18:25:58 +01:00
committed by Space Team
parent dd9332d9e1
commit febac0dd5f
640 changed files with 68168 additions and 6313 deletions
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66094: java.lang.InstantiationError: Foo
// DONT_TARGET_EXACT_BACKEND: JVM
// WITH_STDLIB
// FILE: 1.kt
import kotlin.test.*
@SerialInfo
annotation class Foo(val x: Int, val y: String)
fun box(): String {
val foo = @Suppress("ANNOTATION_CLASS_CONSTRUCTOR_CALL") Foo(42, "OK")
assertEquals(foo.x, 42)
return foo.y
}
// FILE: 2.kt
@Target(AnnotationTarget.ANNOTATION_CLASS)
annotation class SerialInfo
@@ -0,0 +1,13 @@
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
assertEquals(97.0, 'a'.toDouble())
assertEquals(-1, Char.MAX_VALUE.toShort())
assertEquals(32768, Short.MIN_VALUE.toChar().toInt())
assertEquals(-1, Char.MAX_VALUE.toByte())
assertEquals(65408, Byte.MIN_VALUE.toChar().toInt())
assertEquals(0, Float.MIN_VALUE.toChar().toInt())
return "OK"
}
@@ -0,0 +1,21 @@
// WITH_STDLIB
import kotlin.test.*
private fun charCornersMinus(): Int {
val a: Char = 0xFFFF.toChar()
val b: Char = 0.toChar()
return a - b
}
private fun charCornersComparison(): Boolean {
val a = 0xFFFF.toChar()
val b = 0.toChar()
return a < b
}
fun box(): String {
assertEquals(65535, charCornersMinus())
assertFalse(charCornersComparison())
return "OK"
}
@@ -0,0 +1,9 @@
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
assertEquals(1, 0.compareTo(-0.0f))
assertEquals(0, 0.compareTo(+0.0f))
return "OK"
}
@@ -0,0 +1,15 @@
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
assertEquals(1, 0f.compareTo(-0f))
assertEquals(1, 0.0.compareTo(-0.0))
assertEquals(1.0, Double.fromBits(1.0.toBits()))
assertEquals(1.0f, Float.fromBits(1.0f.toBits()))
assertEquals(Double.NaN, Double.fromBits((0 / 0.0).toBits()))
assertEquals(Float.NaN, Float.fromBits((0 / 0f).toBits()))
return "OK"
}
@@ -0,0 +1,20 @@
// WITH_STDLIB
// KT-66079
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
import kotlin.test.*
fun box(): String {
assertEquals(9.223372E18f, Long.MAX_VALUE.toFloat())
assertEquals(-9.223372E18f, Long.MIN_VALUE.toFloat())
assertEquals(-2.147483648E9, Int.MIN_VALUE.toDouble())
assertEquals(2.147483647E9, Int.MAX_VALUE.toDouble())
assertEquals(2147483647, Double.MAX_VALUE.toInt())
assertEquals(0, Float.MIN_VALUE.toLong())
assertEquals(9223372036854775807, Float.MAX_VALUE.toLong())
assertEquals(0, Double.MIN_VALUE.toInt())
return "OK"
}
@@ -0,0 +1,9 @@
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val two = 2.0
assertEquals(2, two.toInt())
return "OK"
}
@@ -0,0 +1,14 @@
// WITH_STDLIB
import kotlin.test.*
// Check that compiler doesn't optimize it to `true`
fun selfCmp1(x: Int) = x + 1 > x
fun selfCmp2(x: Int) = x - 1 < x
fun box(): String {
assertFalse(selfCmp1(Int.MAX_VALUE))
assertFalse(selfCmp2(Int.MIN_VALUE))
return "OK"
}
@@ -0,0 +1,12 @@
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
assertEquals(-2147483648, 1 shl -1)
assertEquals(0, 1 shr -1)
assertEquals(1, 1 shl 32)
assertEquals(1073741823, -1 ushr 2)
assertEquals(-1, -1 shr 2)
return "OK"
}
@@ -0,0 +1,8 @@
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
assertEquals(UInt.MAX_VALUE, UInt.MIN_VALUE - 1u)
return "OK"
}
+15
View File
@@ -0,0 +1,15 @@
// WITH_STDLIB
// KT-66080
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// KT-66081
// IGNORE_BACKEND: WASM
import kotlin.test.*
fun box(): String {
assertFailsWith(ArithmeticException::class, { 5 / 0 })
assertFailsWith(ArithmeticException::class, { 5 % 0 })
assertEquals(1, 5 / try { 0 / 0; 1 } catch (e: ArithmeticException) { 5 })
assertEquals(Double.NaN, 0.0 / 0.0)
return "OK"
}
+26
View File
@@ -0,0 +1,26 @@
// WITH_STDLIB
import kotlin.test.*
object RGBA {
fun packFast(r: Int, g: Int, b: Int, a: Int) = (r shl 0) or (g shl 8) or (b shl 16) or (a shl 24)
fun getFastR(v: Int): Int = (v ushr 0) and 0xFF
fun getFastG(v: Int): Int = (v ushr 8) and 0xFF
fun getFastB(v: Int): Int = (v ushr 16) and 0xFF
fun getFastA(v: Int): Int = (v ushr 24) and 0xFF
fun premultiplyFastInt(v: Int): Int {
val A = getFastA(v) + 1
val RB = (((v and 0x00FF00FF) * A) ushr 8) and 0x00FF00FF
val G = (((v and 0x0000FF00) * A) ushr 8) and 0x0000FF00
return (v and 0x00FFFFFF.inv()) or RB or G
}
}
fun box(): String {
val source = listOf(0xFFFFFFFF.toInt(), 0xFFFFFF77.toInt(), 0x777777FF.toInt(), 0x77777777.toInt())
val expect = listOf(-1, -137, 2000107383, 2000107319)
assertEquals(expect, source.map { RGBA.premultiplyFastInt(it) })
return "OK"
}
+16
View File
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
foo().hashCode()
return "OK"
}
fun foo(): Any {
return Array<Any?>(0, { i -> null })
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Canonical_nameKt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
interface I<U, T> {
fun foo(a: U): T
fun qux(a: T): U
}
//-----------------------------------------------------------------------------//
class A1
class A2
//-----------------------------------------------------------------------------//
class A : I<A1, A2> {
override fun foo(a: A1): A2 { sb.appendLine("A:foo"); return A2() }
override fun qux(a: A2): A1 { sb.appendLine("A:qux"); return A1() }
}
//-----------------------------------------------------------------------------//
fun <U, V> baz(i: I<U, V>, u: U, v:V) {
i.foo(u)
i.qux(v)
}
//-----------------------------------------------------------------------------//
fun box(): String {
baz<A1, A2>(A(), A1(), A2())
assertEquals("A:foo\nA:qux\n", sb.toString())
return "OK"
}
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
testCast(null, false)
testCastToNullable(null, true)
testCastToNullable(TestKlass(), true)
testCastToNullable("", false)
testCastNotNullableToNullable(TestKlass(), true)
testCastNotNullableToNullable("", false)
return "OK"
}
class TestKlass
fun ensure(b: Boolean) {
if (!b) {
throw Error("Error")
}
}
fun testCast(x: Any?, expectSuccess: Boolean) {
try {
x as TestKlass
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun testCastToNullable(x: Any?, expectSuccess: Boolean) {
try {
x as TestKlass?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun testCastNotNullableToNullable(x: Any, expectSuccess: Boolean) {
try {
x as TestKlass?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
open class A() {}
class B(): A() {}
fun castSimple(o: Any) : A = o as A
fun castTest(): Boolean {
val b = B()
castSimple(b)
return true
}
fun box(): String {
if (!castTest()) throw Error()
return "OK"
}
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
interface I
class A() : I {}
class B() {}
//-----------------------------------------------------------------------------//
fun isTypeOf(a: Any?) : Boolean {
return a is A
}
//-----------------------------------------------------------------------------//
fun isTypeNullableOf(a: Any?) : Boolean {
return a is A?
}
//-----------------------------------------------------------------------------//
fun isNotTypeOf(a: Any) : Boolean {
return a !is A
}
//-----------------------------------------------------------------------------//
fun isTypeOfInterface(a: Any) : Boolean {
return a is I
}
//-----------------------------------------------------------------------------//
fun box(): String {
if (!isTypeOf(A())) return "FAIL !isTypeOf(A())"
if (isTypeOf(null)) return "FAIL isTypeOf(null)"
if (!isTypeNullableOf(A())) return "FAIL !isTypeNullableOf(A())"
if (!isTypeNullableOf(null)) return "FAIL !isTypeNullableOf(null)"
if (!isNotTypeOf(B())) return "FAIL !isNotTypeOf(B())"
if (!isTypeOfInterface(A())) return "FAIL !isTypeOfInterface(A())"
return "OK"
}
+12
View File
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
class A {
companion object {
fun foo() = "OK"
}
}
fun box() = A.foo()
+19
View File
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val s = "world"
val i = 1
val res1 = "Hello $s $i ${2 * i}"
if (res1 != "Hello world 1 2") return "FAIL 1: $res1"
val a = "a"
val res2 = "Hello, $a"
if (res2 != "Hello, a") return "FAIL 2: $res2"
return "OK"
}
+20
View File
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
//Original issue here https://youtrack.jetbrains.com/issue/KT-37212
@Suppress("DIVISION_BY_ZERO")
const val fpInfConst = 1.0F / 0.0F
@Suppress("DIVISION_BY_ZERO")
val fpInfVal = 1.0F / 0.0F
fun box(): String {
assertEquals(fpInfConst, Float.POSITIVE_INFINITY)
assertEquals(fpInfVal, Float.POSITIVE_INFINITY)
assertEquals(fpInfConst, fpInfVal)
return "OK"
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun foo() {
Any() as String
}
fun box(): String {
try {
foo()
} catch (e: Throwable) {
return "OK"
}
return "Fail"
}
+37
View File
@@ -0,0 +1,37 @@
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
assertTrue(Reproducer().repro() > 0)
return "OK"
}
// Based on https://youtrack.jetbrains.com/issue/KT-42000#focus=Comments-27-4404934.0-0
val Int.isEven get() = this % 2 == 0
inline operator fun <reified T : Number> T.plus(other: T): T = when (T::class) {
Double::class -> (this as Double) + (other as Double)
Int::class -> (this as Int) + (other as Int)
Long::class -> (this as Long) + (other as Long)
else -> TODO()
} as T
inline fun <reified T : Number> Collection<T>.median(): Double {
val sorted = this.sortedBy {
it.toDouble()
}
return if (size.isEven || size == 1) {
sorted[size / 2]
} else {
sorted[size / 2] + sorted[size / 2 + 1]
}.toDouble()
}
class Reproducer {
private var someListOfLongs = mutableListOf<Long>(1L)
fun repro() = someListOfLongs.median()
}
+14
View File
@@ -0,0 +1,14 @@
// WITH_STDLIB
import kotlin.test.*
// https://youtrack.jetbrains.com/issue/KT-42000
fun box(): String {
assertFailsWith<Error> {
when (1) {
else -> throw Error()
} as String
}
return "OK"
}
+17
View File
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun local_variable(a: Int) : Int {
var b = 0
b = a + 11
return b
}
fun box(): String {
if (local_variable(3) != 14) throw Error()
return "OK"
}
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
//--- Test "eqeq" -------------------------------------------------------------//
fun check_eqeq(a: Any?) = a == null
fun null_check_eqeq1() : Boolean {
return check_eqeq(Any())
}
fun null_check_eqeq2() : Boolean {
return check_eqeq(null)
}
//--- Test "eqeqeq" -----------------------------------------------------------//
fun check_eqeqeq(a: Any?) = a === null
fun null_check_eqeqeq1() : Boolean {
return check_eqeqeq(Any())
}
fun null_check_eqeqeq2() : Boolean {
return check_eqeqeq(null)
}
fun box(): String {
if (null_check_eqeq1()) return "FAIL null_check_eqeq1()"
if (!null_check_eqeq2()) return "FAIL !null_check_eqeq2()"
if (null_check_eqeqeq1()) return "FAIL null_check_eqeqeq1()"
if (!null_check_eqeqeq2()) return "FAIL !null_check_eqeqeq2()"
return "OK"
}
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
open class A
class B : A()
class C
fun foo(a: Any) : A? = a as? A
fun safe_cast_positive(): Boolean {
val b = B()
return foo(b) === b
}
fun safe_cast_negative(): Boolean {
val c = C()
return foo(c) == null
}
fun box(): String {
val safeCastPositive = safe_cast_positive().toString()
val safeCastNegative = safe_cast_negative().toString()
if (safeCastPositive != "true") return "FAIL safeCastPositive"
if (safeCastNegative != "true") return "FAIL safeCastNegative"
return "OK"
}
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val list0 = _arrayOf("K", "o", "t", "l", "i", "n")
val list1 = _arrayOf("l", "a","n", "g", "u", "a", "g", "e")
val list = foo(list0, list1)
val expected = listOf("K", "o", "t", "l", "i", "n", " ", "i", "s", " ", "c", "o", "o", "l", " ", "l", "a", "n", "g", "u", "a", "g", "e")
if (list != expected)
return "FAIL: $list"
return "OK"
}
fun foo(a:Array<out String>, b:Array<out String>) = listOf(*a," ", "i", "s", " ", "c", "o", "o", "l", " ", *b)
fun _arrayOf(vararg arg:String) = arg
@@ -0,0 +1,9 @@
MODULE main
CLASS Statements0Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun simple() {
var a = 238
a++
sb.appendLine(a)
--a
sb.appendLine(a)
}
class Foo() {
val j = 2
var i = 29
fun more() {
i++
}
fun less() {
--i
}
}
fun fields() {
val foo = Foo()
foo.more()
sb.appendLine(foo.i)
foo.less()
sb.appendLine(foo.i)
}
fun box(): String {
simple()
fields()
assertEquals("239\n238\n30\n29\n", sb.toString())
return "OK"
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
open class C {
open fun f() = "<fun:C>"
}
class C1: C() {
override fun f() = super<C>.f() + "<fun:C1>"
}
open class C2: C() {
}
class C3: C2() {
override fun f() = super<C2>.f() + "<fun:C3>"
}
fun box(): String {
val c1f = C1().f()
if (c1f != "<fun:C><fun:C1>") return "FAIL 1: $c1f"
val c3f = C3().f()
if (c3f != "<fun:C><fun:C3>") return "FAIL 2: $c3f"
return "OK"
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
open class C {
open val p1 = "<prop:C>"
}
class C1: C() {
override val p1 = super<C>.p1 + "<prop:C1>"
}
open class C2: C() {
}
class C3: C2() {
override val p1 = super<C2>.p1 + "<prop:C3>"
}
fun box(): String {
val c1p1 = C1().p1
if (c1p1 != "<prop:C><prop:C1>") return "FAIL 1: $c1p1"
val c3p1 = C3().p1
if (c3p1 != "<prop:C><prop:C3>") return "FAIl 2: $c3p1"
return "OK"
}
+43
View File
@@ -0,0 +1,43 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
open class C {
open var p2 = "<prop:C>"
set(value) { field = "<prop:C>" + value }
}
class C1: C() {
override var p2 = super<C>.p2 + "<prop:C1>"
set(value) {
super<C>.p2 = value
field = "<prop:C1>" + super<C>.p2
}
}
open class C2: C() {
}
class C3: C2() {
override var p2 = super<C2>.p2 + "<prop:C3>"
set(value) {
super<C2>.p2 = value
field = "<prop:C3>" + super<C2>.p2
}
}
fun box(): String {
val c1 = C1()
val c3 = C3()
c1.p2 = "zzz"
c3.p2 = "zzz"
val c1p2 = c1.p2
if (c1p2 != "<prop:C1><prop:C>zzz") return "FAIL 1: "
val c3p2 = c3.p2
if (c3p2 != "<prop:C3><prop:C>zzz") return "FAIL 2: "
return "OK"
}
+15
View File
@@ -0,0 +1,15 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val x = Bar(42).x
if (x != 42 ) return "FAIL: $x"
return "OK"
}
class Foo(val x: Int)
typealias Bar = Foo
@@ -0,0 +1,9 @@
MODULE main
CLASS Unchecked_cast1Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
foo<String>("17")
bar<String>("17")
foo<String>(42)
bar<String>(42)
assertEquals("17\n17\n42\n42\n", sb.toString())
return "OK"
}
fun <T> foo(x: Any?) {
val y = x as T
sb.appendLine(y.toString())
}
fun <T> bar(x: Any?) {
val y = x as? T
sb.appendLine(y.toString())
}
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66086
// IGNORE_BACKEND: NATIVE
// KT-66084
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// KT-66085
// IGNORE_BACKEND: WASM
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
try {
val x = cast<String>(Any())
return "FAIL: ${x.length}"
} catch (e: Throwable) {
return "OK"
}
}
fun <T> cast(x: Any?) = x as T
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
testCast<TestKlass>(TestKlass(), true)
testCast<TestKlass>(null, false)
testCastToNullable<TestKlass>(null, true)
return "OK"
}
class TestKlass
fun ensure(b: Boolean) {
if (!b) {
println("Error")
}
}
fun <T : Any> testCast(x: Any?, expectSuccess: Boolean) {
try {
x as T
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
fun <T : Any> testCastToNullable(x: Any?, expectSuccess: Boolean) {
try {
x as T?
} catch (e: Throwable) {
ensure(!expectSuccess)
return
}
ensure(expectSuccess)
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
CI1I2().uncheckedCast<CI1I2>()
CI1I2().uncheckedCast<OtherCI1I2>()
assertFailsWith<ClassCastException> {
Any().uncheckedCast<CI1I2>()
}
return "OK"
}
fun <R : C> Any?.uncheckedCast() where R : I1, R : I2 {
this as R
}
interface I1
interface I2
open class C
class CI1I2 : C(), I1, I2
class OtherCI1I2 : C(), I1, I2
+11
View File
@@ -0,0 +1,11 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
fun myPrintln(a: Any): Unit {}
fun box(): String {
val unit = myPrintln("First")
if (unit.toString() != "kotlin.Unit") return "FAIL 1: $unit"
return "OK"
}
+14
View File
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
fun box(): String {
val x = foo()
if (x.toString() != "kotlin.Unit") return "FAIL: $x"
return "OK"
}
fun foo() {
return Unit
}
+14
View File
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
fun box(): String {
val actual = foo(Unit)
if (actual != "kotlin.Unit") return "FAIL: $actual"
return "OK"
}
fun foo(x: Any): String {
return x.toString()
}
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
fun box(): String {
for (x in 0 .. 8) {
foo(x, Unit)
}
return "OK"
}
var global = 42
fun foo(x: Int, unit: Unit) {
var local = 5
val y: Unit = when (x) {
0 -> {}
1 -> local = 6
2 -> global = 43
3 -> unit
4 -> Unit
5 -> bar()
6 -> return
7 -> {
5
bar()
}
8 -> {
val z: Any = Unit
z as Unit
}
else -> throw Error()
}
if (y !== Unit) {
throw Error("Fail at x = $x")
}
}
fun bar() {
}
+90
View File
@@ -0,0 +1,90 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun foo(a: Int, b : Int): Int = a + b * 2
fun box(): String {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var length = array.size - 1
var sum = 0
array.forEach {
sum += it
}
for (i in array.indices) {
array[i] = 6
}
for (i in 0 until array.size) {
array[i] = 7
}
for (i in array.size - 1 downTo 1) {
array[i] = 7
}
for (it in array) {
sum += it
}
for (i in 0..array.size - 1 step 2) {
array[i] = 7
}
for (i in 0 until array.size step 2) {
array[i] = 7
}
for (i in array.indices step 2) {
array[i] = 6
}
for (i in array.size - 1 downTo 1 step 2) {
array[i] = 7
}
for ((index, value) in array.withIndex()) {
array[index] = 8
}
for ((i, v) in (0..array.size - 1 step 2).withIndex()) {
array[v] = 8
array[i] = 6
}
for (i in array.reversed()) {
sum += i
}
for (i in (0..array.size-1).reversed()) {
array [i] = 10
}
for (i in 0 until array.size) {
array[i] = 7
for (j in 0 until array1.size) {
array1[j] = array[i]
}
}
val size = array.size - 1
val size1 = size
for (i in 0..size1) {
foo(array[i], array[i])
}
for (i in 0..array.size - 2) {
array[i+1] = array[i]
}
if (array.toList() != listOf(7, 7, 7, 7, 7, 7, 7, 7, 7, 7)) return "FAIL 1: ${array.toList()}"
if (array1.toList() != listOf(7, 7, 7)) return "FAIL 2: ${array1.toList()}"
return "OK"
}
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
var needSmallArray = true
val array: Array<Int> = arrayOf(1)
get() = if (needSmallArray) field else arrayOf(1, 2, 3)
fun box(): String {
val a = array
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (index in 0 until array.size) {
a[index] = 6
}
}
return "OK"
}
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
// WITH_REFLECT
import kotlin.test.*
import kotlin.reflect.KProperty
var needSmallArray = true
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Array<Int> {
return if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
}
class WithDelegates {
val array by Delegate()
}
fun box(): String {
val obj = WithDelegates()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
return "OK"
}
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
class Foo(size: Int) {
val array = IntArray(size)
}
class Bar {
val smallFoo = Foo(1)
val largeFoo = Foo(10)
val smallArray = smallFoo.array
val largeArray = largeFoo.array
}
fun box(): String {
val bar = Bar()
assertFailsWith<IndexOutOfBoundsException> {
for (index in 0 until bar.largeArray.size) {
bar.smallArray[index] = 6
}
}
return "OK"
}
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
class First(initArray: Array<Int>) {
val array = initArray
}
class Second(initArray: Array<Int>){
val first = First(initArray)
}
class Third(initArray: Array<Int>) {
val second = Second(initArray)
}
fun box(): String {
val a = Third(arrayOf(1, 2, 3, 4, 5))
val b = Third(arrayOf(1, 2))
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..a.second.first.array.size-1) {
b.second.first.array[i] = 6
}
}
return "OK"
}
+62
View File
@@ -0,0 +1,62 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array[i * 2] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array1[i] = 6
}
}
var a = array.size - 1
val b = ++a
val c = b
assertFailsWith<IndexOutOfBoundsException> {
for (i in c downTo 0) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size + 1 downTo 0) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo -1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size downTo 0) {
array[i] = 6
}
}
return "OK"
}
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = UIntArray(10) { 0U }
val array1 = UIntArray(3) { 0U }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0 step 2) {
array[j] = 6U
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 1 step 2) {
array[i + 1] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 1 step 2) {
array1[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (array.size / 0.2).toInt() downTo 1 step 2) {
array[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo -3 step 2) {
array[i] = 6U
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size downTo 1 step 2) {
array[i] = 6U
}
}
return "OK"
}
+19
View File
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0 }
assertFailsWith<IndexOutOfBoundsException> {
array.forEachIndexed { index, _ ->
array[index + 1] = 1
}
}
return "OK"
}
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0 }
val array1 = Array(3) { 0 }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array[i + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array1[i] = 6
}
}
return "OK"
}
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array1[i] = 6
}
}
return "OK"
}
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array[j] = 6
j++
}
}
var length = array.size - 1
length = 2 * length
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..length) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array[i + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size + 1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -1..array.size - 1) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size) {
array[i] = 6
}
}
return "OK"
}
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size + 1 step 2) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -1..array.size - 1 step 2) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size step 2) {
array[i] = 6
}
}
return "OK"
}
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0..array.size-1).reversed()) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0 until array.size).reversed()) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0..array.size).reversed()) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in (array.size downTo 0).reversed()) {
array[i] = 6
}
}
return "OK"
}
+40
View File
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 0L }
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array[i - 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array1[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size + 10) {
array[i] = 6
}
}
return "OK"
}
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = CharArray(10) { '0' }
val array1 = CharArray(3) { '0' }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array[j] = '6'
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array[i + 3] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array1[i] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until (array.size/0.5).toInt() step 2) {
array[i] = '6'
}
}
assertFailsWith<IndexOutOfBoundsException> {
for (i in -array.size until array.size step 2) {
array[i] = '6'
}
}
return "OK"
}
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val array = Array(10) { 100 }
val array1 = Array(3) { 0 }
var j = 8
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[j] = 6
j++
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[index + 1] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[value] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((i, v) in (0..array.size + 30 step 2).withIndex()) {
array[i] = 6
}
}
assertFailsWith<IndexOutOfBoundsException> {
for ((i, v) in (0..array.size).withIndex()) {
array[v] = 8
}
}
return "OK"
}
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
// WITH_REFLECT
import kotlin.reflect.KProperty
import kotlin.test.*
var needSmallArray = true
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Array<Int> {
return if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
}
open class Base {
open val array = Array(10) { 100 }
val array1 by Delegate()
}
class Child : Base() {
override val array: Array<Int>
get() = if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
fun box(): String {
val obj = Child()
val base = Base()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array1.size-1) {
needSmallArray = true
obj.array1[i] = 6
needSmallArray = false
}
}
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
base.array[i] = 6
needSmallArray = false
}
}
return "OK"
}
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// KT-66100: AssertionError: Expected an exception of class IndexOutOfBoundsException to be thrown, but was completed successfully.
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// WITH_STDLIB
import kotlin.test.*
var needSmallArray = true
class WithGetter() {
val array: Array<Int>
get() = if (needSmallArray)
Array(10) { 100 }
else
Array(100) { 100 }
}
fun box(): String {
val obj = WithGetter()
needSmallArray = false
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
needSmallArray = false
}
}
return "OK"
}
+59
View File
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun <T> areSame(arg1: T, arg2: T): Boolean {
return arg1 === arg2
}
fun Boolean.oneIfTrueElseZero(): Int {
return if (this) 1 else 0
}
fun box(): String {
var acc = 0
val range = 1000
for (i in arrayOf(false, true)) {
for (j in arrayOf(false, true)) {
acc += areSame(i, j).oneIfTrueElseZero()
}
}
if (acc != 2) "FAIL 1: $acc"
acc = 0
for (i in Byte.MIN_VALUE..Byte.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 2: $acc"
acc = 0
for (i in Short.MIN_VALUE..Short.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 3: $acc"
acc = 0
for (i in 0.toChar()..range.toChar()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 4: $acc"
acc = 0
for (i in -range..range) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 5: $acc"
acc = 0
for (i in -range.toLong()..range.toLong()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 6: $acc"
return "OK"
}
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
class Box<T>(t: T) {
var value = t
}
fun box(): String {
val box: Box<Int> = Box<Int>(17)
if (box.value != 17) return "FAIL 1: ${box.value}"
val nonConst = 17
val box2: Box<Int> = Box<Int>(nonConst)
if (box2.value != 17) return "FAIL 1: ${box2.value}"
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing1Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun foo(arg: Any) {
sb.appendLine(arg.toString())
}
fun box(): String {
foo(1)
foo(2u)
foo(false)
foo("Hello")
val nonConstInt = 1
val nonConstUInt = 2u
val nonConstBool = false
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstUInt)
foo(nonConstBool)
foo(nonConstString)
assertEquals("""
1
2
false
Hello
1
2
false
Hello
""".trimIndent(), sb.toString())
return "OK"
}
+18
View File
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val FALSE: Boolean? = false
if (FALSE != null) {
do {
return "OK"
} while (FALSE)
}
return "FAIL"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing11Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
class Foo(val value: Int?) {
fun foo() {
printInt(if (value != null) value else 42)
}
}
fun box(): String {
Foo(17).foo()
Foo(null).foo()
assertEquals("17\n42\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing12Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun foo(x: Number) {
sb.appendLine(x.toByte())
}
fun box(): String {
foo(18)
val nonConst = 18
foo(nonConst)
assertEquals("18\n18\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing13Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+44
View File
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun is42(x: Any?) {
sb.appendLine(x == 42)
sb.appendLine(42 == x)
}
fun box(): String {
is42(16)
is42(42)
is42("42")
val nonConst16 = 16
val nonConst42 = 42
val nonConst42String = "42"
is42(nonConst16)
is42(nonConst42)
is42(nonConst42String)
assertEquals("""
false
false
true
true
false
false
false
false
true
true
false
false
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing14Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
42.println()
val nonConst = 42
nonConst.println()
assertEquals("42\n42\n", sb.toString())
return "OK"
}
fun <T> T.println() = sb.appendLine(this)
+20
View File
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val res1 = foo(17)
if (res1 != 17) return "FAIL 1: $res1"
val nonConst = 17
val res2 = foo(nonConst)
if (res2 != 17) return "FAIL 2: $res2"
return "OK"
}
fun <T : Int> foo(x: T): Int = x
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing2Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x.toString())
fun printBoolean(x: Boolean) = sb.appendLine(x.toString())
fun printUInt(x: UInt) = sb.appendLine(x.toString())
fun foo(arg: Any) {
if (arg is Int)
printInt(arg)
else if (arg is Boolean)
printBoolean(arg)
else if (arg is UInt)
printUInt(arg)
else
sb.appendLine("other")
}
fun box(): String {
foo(1)
foo(2u)
foo(true)
foo("Hello")
val nonConstInt = 1
val nonConstUInt = 2u
val nonConstBool = true
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstUInt)
foo(nonConstBool)
foo(nonConstString)
assertEquals("""
1
2
true
other
1
2
true
other
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing3Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Int?) {
if (arg != null)
printInt(arg)
}
fun box(): String {
foo(42)
val nonConst = 42
foo(nonConst)
assertEquals("42\n42\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing4Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+26
View File
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any?) {
if (arg is Int? && arg != null)
printInt(arg)
}
fun box(): String {
foo(16)
val nonConst = 16
foo(nonConst)
assertEquals("16\n16\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing5Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Int?) {
printInt(arg ?: 16)
}
fun box(): String {
foo(null)
foo(42)
val nonConstNull = null
val nonConstInt = 42
foo(nonConstNull)
foo(nonConstInt)
assertEquals("16\n42\n16\n42\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing6Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any) {
printInt(arg as? Int ?: 16)
}
fun box(): String {
foo(42)
foo("Hello")
val nonConstInt = 42
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstString)
assertEquals("42\n16\n42\n16\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing7Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any) {
val argAsInt = try {
arg as Int
} catch (e: ClassCastException) {
0
}
printInt(argAsInt)
}
fun box(): String {
foo(1)
foo("Hello")
val nonConstInt = 1
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstString)
assertEquals("1\n0\n1\n0\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing8Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+38
View File
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun foo(vararg args: Any?) {
for (arg in args) {
sb.appendLine(arg.toString())
}
}
fun box(): String {
foo(1, null, true, "Hello")
val nonConstInt = 1
val nonConstNull = null
val nonConstBool = true
val nonConstString = "Hello"
foo(nonConstInt, nonConstNull, nonConstBool, nonConstString)
assertEquals("""
1
null
true
Hello
1
null
true
Hello
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing9Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+38
View File
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun foo(vararg args: Any?) {
for (arg in args) {
sb.appendLine(arg.toString())
}
}
fun bar(vararg args: Any?) {
foo(1, *args, 2, *args, 3)
}
fun box(): String {
bar(null, true, "Hello")
assertEquals("""
1
null
true
Hello
2
null
true
Hello
3
""".trimIndent(), sb.toString())
return "OK"
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// KT-54635: expected:<[OK]> but was:<[FAIL 1: 0]>
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// KT-66099: CompileError: WebAssembly.Module(): Compiling function #3415:"box" failed: Invalid types for ref.cast null: local.get of type f64 has to be in the same reference type hierarchy as (ref 686) @+237036
// IGNORE_BACKEND: WASM
// WITH_STDLIB
import kotlin.test.*
// Reproducer is copied from FloatingPointParser.unaryMinus()
inline fun <reified T> unaryMinus(value: T): T {
return when (value) {
is Float -> -value as T
is Double -> -value as T
else -> throw NumberFormatException()
}
}
fun box(): String {
val res1 = unaryMinus(0.0).toString()
if (res1 != "-0.0") return "FAIL 1: $res1"
val res2 = unaryMinus(0.0f).toString()
if (res2 != "-0.0") return "FAIL 2: $res2"
return "OK"
}
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun advanced_when2(i: Int): Int {
var value = 1
when (i) {
10 -> {val v = 42; value = v}
11 -> {val v = 43; value = v}
12 -> {val v = 44; value = v}
}
return value
}
fun box(): String {
val res = advanced_when2(10)
if (res != 42) return "FAIL $res"
return "OK"
}
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun advanced_when5(i: Int): Int {
when (i) {
0 -> { val v = 42; return v}
1 -> { val v = 42; return v}
2 -> { val v = 42; return v}
3 -> { val v = 42; return v}
4 -> { val v = 42; return v}
else -> return 24
}
}
fun box(): String {
val res = advanced_when5(5)
if (res != 24) return "FAIL $res"
return "OK"
}
+19
View File
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun if_else(b: Boolean): Int {
if (b) return 42
else return 24
}
fun box(): String {
val res = if_else(false)
if (res != 24) return "FAIL: $res"
return "OK"
}
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun when2(i: Int): Int {
when (i) {
0 -> return 42
else -> return 24
}
}
fun box(): String {
val res = when2(0)
if (res != 42) return "FAIL $res"
return "OK"
}
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun when5(i: Int): Int {
when (i) {
0 -> return 42
1 -> return 4
2 -> return 3
3 -> return 2
4 -> return 1
}
return 24
}
fun box(): String {
val res = when5(5)
if (res != 24) return "FAIL $res"
return "OK"
}
+25
View File
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun when5(i: Int): Int {
when (i) {
0 -> return 42
1 -> return 4
2 -> return 3
3 -> return 2
4 -> return 1
else -> return 24
}
}
fun box(): String {
val res = when5(2)
if (res != 3) return "FAIL $res"
return "OK"
}
+16
View File
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun foo() {
}
fun box(): String {
if (true) foo() else foo()
return "OK"
}
+18
View File
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
main(emptyArray())
return "OK"
}
fun main(args: Array<String>) {
val b = args.size < 1
val x = if (b) Any() else throw Error()
}

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