[FIR] Extract K2 MPP test data to the separated directory

This commit is contained in:
Ivan Kochurkin
2023-02-27 20:07:17 +01:00
committed by Space Team
parent 5b2a1feaf0
commit ee53c5780f
84 changed files with 4036 additions and 500 deletions
@@ -1,7 +1,8 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: default argument mapping in MPP isn't designed yet
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// FILE: common.kt
public expect fun <T> Array<out T>.copyInto(
@@ -1,7 +1,8 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: default argument mapping in MPP isn't designed yet
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// FILE: common.kt
expect interface I {
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// FILE: lib.kt
expect interface I {
@@ -1,8 +1,7 @@
// IGNORE_BACKEND: WASM
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// IGNORE_BACKEND: WASM, JS_IR, JS_IR_ES6, NATIVE
// WASM_MUTE_REASON: EXPECT_DEFAULT_PARAMETERS
// IGNORE_BACKEND_K2: JVM_IR, NATIVE
// FIR status: default argument mapping in MPP isn't designed yet
// IGNORE_BACKEND_K2: JVM, JVM_IR
// FIR status: outdated code (expect and actual in the same module)
// !LANGUAGE: +MultiPlatformProjects
// KT-41901
@@ -1,6 +1,7 @@
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, NATIVE
// FIR status: default argument mapping in MPP isn't designed yet
// IGNORE_BACKEND_K2: ANY
// !LANGUAGE: +MultiPlatformProjects
// FIR status: outdated code (expect and actual in the same module)
// FILE: common.kt
class Receiver(val value: String)
@@ -1,6 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// FIR status: default argument mapping in MPP isn't designed yet
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
@@ -1,7 +1,8 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, NATIVE
// FIR status: default argument mapping in MPP isn't designed yet
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
open class A() {
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// FILE: lib.kt
expect interface I {
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// FILE: lib.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// FILE: common.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// FILE: common.kt
@@ -4,6 +4,7 @@
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_K2: JS_IR
// FILE: lib.kt
@@ -1,5 +1,6 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: NATIVE
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// WITH_COROUTINES
@@ -1,7 +1,7 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, NATIVE
// FIR status: In FIR, declaring the same `expect` and `actual` classes in one compiler module is not possible (see KT-55177).
// FILE: common.kt
@@ -2,6 +2,8 @@
// IGNORE_BACKEND_K2: JVM_IR, JS_IR
// FIR status: expect/actual in the same module (ACTUAL_WITHOUT_EXPECT)
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// WITH_STDLIB
// FILE: common.kt
@@ -1,6 +1,7 @@
// IGNORE_BACKEND_K2: JVM_IR, JS_IR, NATIVE
// FIR status: expect/actual in the same module (ACTUAL_WITHOUT_EXPECT)
// IGNORE_BACKEND_K2: ANY
// FIR status: outdated code (expect and actual in the same module)
// !LANGUAGE: +MultiPlatformProjects
// FILE: common.kt
package test
@@ -0,0 +1,99 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K1: JVM, JVM_IR
// !LANGUAGE: +MultiPlatformProjects
// WITH_REFLECT
// MODULE: common
// FILE: common.kt
// See compiler/testData/diagnostics/tests/multiplatform/defaultArguments/annotationsViaActualTypeAlias2.kt
// This test checks the same behavior but against the Java implementation compiled to the .class file (as opposed to a .java source file).
// Enum annotation argument is commented below, because to be able to resolve E in Jnno.java we have to have a multi-module test where
// one of the modules also contains Java files, and that is too complicated for our test infrastructure at the moment.
import kotlin.reflect.KClass
expect annotation class Anno(
val b: Byte = 1.toByte(),
val c: Char = 'x',
val d: Double = 3.14,
val f: Float = -2.72f,
val i: Int = 42424242,
val i2: Int = 53535353,
val j: Long = 239239239239239L,
val j2: Long = 239239L,
val s: Short = 42.toShort(),
val z: Boolean = true,
val ba: ByteArray = [(-1).toByte()],
val ca: CharArray = ['y'],
val da: DoubleArray = [-3.14159],
val fa: FloatArray = [2.7218f],
val ia: IntArray = [424242],
val ja: LongArray = [239239239239L, 239239L],
val sa: ShortArray = [(-43).toShort()],
val za: BooleanArray = [false, true],
val str: String = "fizz",
val k: KClass<*> = Number::class,
// val e: E = E.E1,
// TODO: val a: A = A("1"),
val stra: Array<String> = ["bu", "zz"],
val ka: Array<KClass<*>> = [Double::class, String::class, LongArray::class, Array<Array<Array<Int>>>::class, Unit::class]
// val ea: Array<E> = [E.E2, E.E3],
// TODO: val aa: Array<A> = [A("2"), A("3")]
)
// MODULE: lib()()(common)
// FILE: Jnno.java
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Jnno {
byte b() default 1;
char c() default 'x';
double d() default 3.14;
float f() default -2.72f;
int i() default 42424242;
int i2() default 21212121 + 32323232;
long j() default 239239239239239L;
long j2() default 239239;
short s() default 42;
boolean z() default true;
byte[] ba() default {-1};
char[] ca() default {'y'};
double[] da() default {-3.14159};
float[] fa() default {2.7218f};
int[] ia() default {424242};
long[] ja() default {239239239239L, 239239};
short[] sa() default {-43};
boolean[] za() default {false, true};
String str() default "fi" + "zz";
Class<?> k() default Number.class;
// E e() default E.E1;
// TODO: A a() default @A("1");
String[] stra() default {"bu", "zz"};
Class<?>[] ka() default {double.class, String.class, long[].class, Integer[][][].class, void.class};
// E[] ea() default {E.E2, E.E3};
// TODO: A[] aa() default {@A("2"), @A("3")};
}
// FILE: anno.kt
actual typealias Anno = Jnno
// MODULE: main(lib)
// FILE: main.kt
annotation class A(val value: String)
@Anno
fun test() {}
fun box(): String {
// We don't need to check the contents, just check that there are no anomalities in the bytecode by loading annotations
::test.annotations.toString()
return "OK"
}
@@ -0,0 +1,28 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K1: JVM, JVM_IR
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
@file:JvmMultifileClass
@file:JvmName("Test")
package test
expect class Foo {
val value: String
}
// MODULE: jvm()()(common)
// FILE: jvm.kt
@file:JvmMultifileClass
@file:JvmName("Test")
package test
actual class Foo(actual val value: String)
fun box(): String {
return Foo("OK").value
}
@@ -0,0 +1,42 @@
// !LANGUAGE: +MultiPlatformProjects
// !OPT_IN: kotlin.ExperimentalMultiplatform
// IGNORE_BACKEND: NATIVE, WASM
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// IGNORE_BACKEND_K2: JS_IR
// WITH_STDLIB
// MODULE: common
// FILE: expected.kt
package a
@OptionalExpectation
expect annotation class A(val x: Int)
@OptionalExpectation
expect annotation class B(val s: String) {
@OptionalExpectation
annotation class C(val a: Boolean)
}
// MODULE: library()()(common)
// FILE: library.kt
package a
actual annotation class A(actual val x: Int)
// MODULE: main(library)
// FILE: main.kt
package usage
import a.A
import a.B
@A(42)
@B("OK")
@B.C(true)
fun box(): String {
return "OK"
}
@@ -0,0 +1,31 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
package test
expect val v: String
expect val Char.extensionVal: String
expect var String.extensionVar: Char
// MODULE: platform()()(common)
// FILE: platform.kt
package test
actual val v: String = ""
actual val Char.extensionVal: String
get() = toString()
actual var String.extensionVar: Char
get() = this[0]
set(value) {}
fun box(): String =
v + 'O'.extensionVal + "K".extensionVar
@@ -0,0 +1,35 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K1: JVM, JVM_IR
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect class Foo(a: String = "", b: Int = 42)
// MODULE: jvm()()(common)
// FILE: J.java
public class J {
public static void test() {
new Foo();
new Foo("", 42);
}
}
// FILE: jvm.kt
import kotlin.test.assertEquals
actual class Foo actual constructor(a: String, b: Int) {
init {
assertEquals("", a)
assertEquals(42, b)
}
}
fun box(): String {
J.test()
return "OK"
}
@@ -0,0 +1,38 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K1: ANY
// TARGET_BACKEND: JVM
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect annotation class A1(val x: Int, val y: String = "OK")
expect annotation class A2(val x: Int = 42, val y: String = "OK")
@A1(0)
@A2
fun test() {}
// MODULE: jvm()()(common)
// FILE: jvm.kt
import kotlin.test.assertEquals
actual annotation class A1(actual val x: Int, actual val y: String)
actual annotation class A2(actual val x: Int, actual val y: String = "OK")
fun box(): String {
val anno = Class.forName("CommonKt").getDeclaredMethod("test").annotations
val a1 = anno.single { it.annotationClass == A1::class } as A1
assertEquals(0, a1.x)
assertEquals("OK", a1.y)
val a2 = anno.single { it.annotationClass == A2::class } as A2
assertEquals(42, a2.x)
assertEquals("OK", a2.y)
return "OK"
}
@@ -0,0 +1,32 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
public expect fun <T> Array<out T>.copyInto(
destination: Array<T>, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size
): Array<T>
// MODULE: platform()()(common)
// FILE: platform.kt
// This test should be updated once KT-22818 is fixed; default values are not allowed in the actual function
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
public actual fun <T> Array<out T>.copyInto(
destination: Array<T>, destinationOffset: Int = 42, startIndex: Int = 43, endIndex: Int = size + 44
): Array<T> {
destination as Array<Int>
destination[0] = destinationOffset
destination[1] = startIndex
destination[2] = endIndex
return destination
}
fun box(): String {
val a = Array<Int>(3) { it }
val result = a.copyInto(a)
return if (result[0] == 42 && result[1] == 43 && result[2] == 47) "OK"
else "Fail: ${result[0]} ${result[1]} ${result[2]}"
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
expect interface I {
fun test(source: String = "expect")
}
expect interface J : I
// MODULE: platform()()(common)
// FILE: platform.kt
actual interface I {
// This test should be updated once KT-22818 is fixed; default values are not allowed in the actual function
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
actual fun test(source: String = "actual")
}
actual interface J : I {
override fun test(source: String) {
if (source != "actual") throw AssertionError(source)
}
}
class K : J
fun box(): String {
K().test()
return "OK"
}
@@ -0,0 +1,26 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect class Foo(a: String, b: Int = 0, c: Double? = null)
// MODULE: platform()()(common)
// FILE: platform.kt
import kotlin.test.assertEquals
actual class Foo actual constructor(a: String, b: Int, c: Double?) {
val result: String = a + "," + b + "," + c
}
fun box(): String {
assertEquals("OK,0,null", Foo("OK").result)
assertEquals("OK,42,null", Foo("OK", 42).result)
assertEquals("OK,42,3.14", Foo("OK", 42, 3.14).result)
return "OK"
}
@@ -0,0 +1,72 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
expect interface I {
fun foo(x: Int = 1): Unit
}
// MODULE: main()()(common)
// FILE: main.kt
var log = ""
fun log(a: String) {
log += a + ";"
}
interface C {
fun foo(x: Int): Unit {
log("C.foo($x)")
}
}
actual interface I {
actual fun foo(x: Int): Unit
}
class G(c: C) : C by c, I
class H(c: C) : I, C by c
fun test1() {
log = ""
val g1 = G(object: C {})
g1.foo(2)
g1.foo()
val g2 = G(object: C {
override fun foo(x: Int) {
log("[2] object:C.foo($x)")
}
})
g2.foo(2)
g2.foo()
}
fun test2() {
log = ""
val h1 = H(object: C {})
h1.foo(2)
h1.foo()
val h2 = H(object: C {
override fun foo(x: Int) {
log("[2] object:C.foo($x)")
}
})
h2.foo(2)
h2.foo()
}
fun box(): String {
test1()
if (log != "C.foo(2);C.foo(1);[2] object:C.foo(2);[2] object:C.foo(1);") return "fail1: $log"
test2()
if (log != "C.foo(2);C.foo(1);[2] object:C.foo(2);[2] object:C.foo(1);") return "fail2: $log"
return "OK"
}
@@ -0,0 +1,23 @@
// IGNORE_BACKEND: JS_IR, JS_IR_ES6, NATIVE, WASM
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS
// WASM_MUTE_REASON: EXPECT_DEFAULT_PARAMETERS
// !LANGUAGE: +MultiPlatformProjects
// ISSUE: KT-41901
// MODULE: common
// FILE: common.kt
expect class C {
val value: String
fun test(result: String = value): String
}
// MODULE: platform()()(common)
// FILE: platform.kt
actual class C(actual val value: String) {
actual fun test(result: String): String = result
}
fun box() = C("Fail").test("OK")
@@ -0,0 +1,19 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
class Receiver(val value: String)
expect fun Receiver.test(result: String = value): String
// MODULE: platform()()(common)
// FILE: platform.kt
actual fun Receiver.test(result: String): String {
return result
}
fun box() = Receiver("Fail").test("OK")
@@ -0,0 +1,37 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect fun topLevel(a: String, b: Int = 0, c: Double? = null): String
expect class Foo() {
fun member(a: String, b: Int = 0, c: Double? = null): String
}
// MODULE: platform()()(common)
// FILE: platform.kt
import kotlin.test.assertEquals
actual fun topLevel(a: String, b: Int, c: Double?): String = a + "," + b + "," + c
actual class Foo actual constructor() {
actual fun member(a: String, b: Int, c: Double?): String = a + "," + b + "," + c
}
fun box(): String {
assertEquals("OK,0,null", topLevel("OK"))
assertEquals("OK,42,null", topLevel("OK", 42))
assertEquals("OK,42,3.14", topLevel("OK", 42, 3.14))
val foo = Foo()
assertEquals("OK,0,null", foo.member("OK"))
assertEquals("OK,42,null", foo.member("OK", 42))
assertEquals("OK,42,3.14", foo.member("OK", 42, 3.14))
return "OK"
}
@@ -0,0 +1,21 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect fun foo(a: String, b: String = "O"): String
// MODULE: lib()()(common)
// FILE: lib.kt
actual fun foo(a: String, b: String) = a + b
// MODULE: main(lib)
// FILE: main.kt
fun box(): String {
return foo("") + foo("K", "")
}
@@ -0,0 +1,29 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
open class A() {
fun member(a: String, b: Int = 0, c: Double? = null): String = a + "," + b + "," + c
}
expect class B() : A
// MODULE: platform()()(common)
// FILE: platform.kt
import kotlin.test.assertEquals
actual class B actual constructor() : A()
fun box(): String {
val b = B()
assertEquals("OK,0,null", b.member("OK"))
assertEquals("OK,42,null", b.member("OK", 42))
assertEquals("OK,42,3.14", b.member("OK", 42, 3.14))
return "OK"
}
@@ -0,0 +1,33 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect open class A() {
fun member(a: String, b: Int = 0, c: Double? = null): String
}
expect class B() : A
// MODULE: platform()()(common)
// FILE: platform.kt
import kotlin.test.assertEquals
actual open class A actual constructor() {
actual fun member(a: String, b: Int, c: Double?): String = a + "," + b + "," + c
}
actual class B actual constructor() : A()
fun box(): String {
val b = B()
assertEquals("OK,0,null", b.member("OK"))
assertEquals("OK,42,null", b.member("OK", 42))
assertEquals("OK,42,3.14", b.member("OK", 42, 3.14))
return "OK"
}
@@ -0,0 +1,21 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
expect interface I {
fun f(p: String = "OK"): String
}
// MODULE: platform()()(common)
// FILE: platform.kt
actual interface I {
actual fun f(p: String): String
}
class Impl : I {
override fun f(p: String) = p
}
fun box() = Impl().f()
@@ -0,0 +1,34 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect open class C() {
open fun f(p: Int = 2) : String
}
// MODULE: platform()()(common)
// FILE: platform.kt
import kotlin.test.assertEquals
actual open class C {
actual open fun f(p: Int) = "C" + p
}
open class D : C() {
override open fun f(p: Int) = "D" + p
}
fun box(): String {
assertEquals("C2", C().f())
assertEquals("C9", C().f(9))
assertEquals("D2", D().f())
assertEquals("D5", D().f(5))
return "OK"
}
@@ -0,0 +1,38 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect open class A() {
open fun f(p: Int = 1) : String
}
expect open class B : A {
override open fun f(p: Int) : String
}
// MODULE: platform()()(common)
// FILE: platform.kt
import kotlin.test.assertEquals
actual open class A {
actual open fun f(p: Int) = "A" + p
}
actual open class B : A() {
actual override open fun f(p: Int) = "B" + p
}
fun box(): String {
assertEquals("A1", A().f())
assertEquals("A9", A().f(9))
assertEquals("B1", B().f())
assertEquals("B5", B().f(5))
return "OK"
}
@@ -0,0 +1,52 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
package foo
expect interface H {
fun foo(x: String = "default"): String
}
// MODULE: platform()()(common)
// FILE: platform.kt
package foo
actual interface H {
actual fun foo(x: String): String
}
interface I: H {
override fun foo(x: String): String = "I.foo($x)"
}
interface J : I {
override fun foo(x: String): String
}
interface K : J {
override fun foo(x: String): String = "K.foo($x)"
}
class A : I
class B : K
fun box(): String {
val a = A()
var r = a.foo()
if (r != "I.foo(default)") return "fail: A.foo()"
r = a.foo("Q")
if (r != "I.foo(Q)") return "fail A.foo(Q): $r"
val b = B()
r = b.foo()
if (r != "K.foo(default)") return "fail B.foo(): $r"
r = b.foo("W")
if (r != "K.foo(W)") return "fail B.foo(W): $r"
return "OK"
}
@@ -0,0 +1,37 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect inline fun topLevel(a: String, b: Int = 0, c: () -> Double? = { null }): String
expect class Foo() {
inline fun member(a: String, b: Int = 0, c: () -> Double? = { null }): String
}
// MODULE: platform()()(common)
// FILE: platform.kt
import kotlin.test.assertEquals
actual inline fun topLevel(a: String, b: Int, c: () -> Double?): String = a + "," + b + "," + c()
actual class Foo actual constructor() {
actual inline fun member(a: String, b: Int, c: () -> Double?): String = a + "," + b + "," + c()
}
fun box(): String {
assertEquals("OK,0,null", topLevel("OK"))
assertEquals("OK,42,null", topLevel("OK", 42))
assertEquals("OK,42,3.14", topLevel("OK", 42, { 3.14 }))
val foo = Foo()
assertEquals("OK,0,null", foo.member("OK"))
assertEquals("OK,42,null", foo.member("OK", 42))
assertEquals("OK,42,3.14", foo.member("OK", 42, { 3.14 }))
return "OK"
}
@@ -0,0 +1,35 @@
// !LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K1: JVM, JVM_IR
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect fun foo(j: Int, i: Int = -1)
// MODULE: main()()(common)
// FILE: J.java
public class J {
public static String test() {
JvmKt.foo(-1);
JvmKt.foo(5, 5);
return "OK";
}
}
// FILE: jvm.kt
import kotlin.test.assertEquals
@JvmOverloads
actual fun foo(j: Int, i: Int) {
assertEquals(j, i)
}
fun box(): String {
foo(-1)
foo(5, 5)
return J.test();
}
@@ -0,0 +1,39 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect open class C() {
open fun f(p: Int = 1) : String
open fun f2(p1: Int = 1, p2: Int = 2) : String
open fun ff(p1: Int, p2: Int = 2) : String
open fun fff(p1: Int, p2: Int, p3: Int = 3) : String
open fun fffx(p1: Int, p2: Int = 4, p3: Int = 5) : String
}
// MODULE: platform()()(common)
// FILE: platform.kt
import kotlin.test.assertEquals
actual open class C {
actual open fun f(p: Int) = "f" + p
actual open fun f2(p1: Int, p2: Int) = "f2" + p1 + "" + p2
actual open fun ff(p1: Int, p2: Int) = "ff" + p1 + "" + p2
actual open fun fff(p1: Int, p2: Int, p3: Int) = "fff" + p1 + "" + p2 + "" + p3
actual open fun fffx(p1: Int, p2: Int, p3: Int) = "fffx" + p1 + "" + p2 + "" + p3
}
fun box(): String {
assertEquals("f1", C().f())
assertEquals("f212", C().f2())
assertEquals("ff12", C().ff(1))
assertEquals("fff123", C().fff(1, 2))
assertEquals("fffx345", C().fffx(3))
return "OK"
}
@@ -0,0 +1,19 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
expect inline fun <T> get(p: String = "OK"): String
// MODULE: platform()()(common)
// FILE: platform.kt
actual inline fun <T> get(p: String): String {
return p
}
fun box(): String {
return get<String>()
}
@@ -0,0 +1,33 @@
// WITH_STDLIB
// IGNORE_BACKEND: JS_IR, JS_IR_ES6, WASM, NATIVE
// IGNORE_BACKEND_K1: JS, JVM, JVM_IR
// JS IR & Wasm: https://youtrack.jetbrains.com/issue/KT-51225
// !LANGUAGE: +MultiPlatformProjects
// ISSUE: KT-51156
// MODULE: common
// FILE: common.kt
expect class C(e: E = E.O) {
enum class E {
O, K
}
}
// MODULE: platform()()(common)
// FILE: platform.kt
actual class C actual constructor(e: E) {
val result = e.name
actual enum class E {
O, K
}
}
// MODULE: main(platform)
// FILE: main.kt
fun box(): String {
return C().result + C(C.E.K).result
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
class B(val value: Int)
expect fun test(a: Int = 2, b: Int = B(a * 2).value, c: String = "${b}$a"): String
// MODULE: platform()()(common)
// FILE: platform.kt
actual fun test(a: Int, b: Int, c: String): String = c
fun box(): String {
val result = test()
return if (result == "42") "OK" else "Fail: $result"
}
@@ -0,0 +1,44 @@
// IGNORE_BACKEND: NATIVE, WASM
// WASM_MUTE_REASON: EXPECT_DEFAULT_PARAMETERS
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE, JVM, JVM_IR
// IGNORE_BACKEND_K1: JS, JS_IR, JS_IR_ES6
// MODULE: common
// FILE: common.kt
package foo
expect open class A {
open fun foo(x: Int = 20, y: Int = 3): Int
}
// MODULE: platform()()(common)
// FILE: main.kt
package foo
actual open class A {
actual open fun foo(x: Int, y: Int) = x + y
}
open class B : A() {
override fun foo(x: Int, y: Int) = 0
fun bar1() = super.foo()
fun bar2() = super.foo(30)
fun bar3() = super.foo(y = 4)
}
fun box(): String {
val v1 = B().bar1()
if (v1 != 23) return "fail1: $v1"
val v2 = B().bar2()
if (v2 != 33) return "fail2: $v2"
val v3 = B().bar3()
if (v3 != 24) return "fail3: $v3"
return "OK"
}
@@ -0,0 +1,38 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// WITH_COROUTINES
// MODULE: common
// FILE: common.kt
expect interface I {
suspend fun f(p: Int = 1): String
}
// MODULE: main()()(common)
// FILE: main.kt
import kotlin.coroutines.*
import helpers.*
actual interface I {
actual suspend fun f(p: Int): String
}
class II : I {
override suspend fun f(p: Int): String =
if (p == 1) "OK" else "Fail: $p"
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var res = "FAIL"
builder {
res = II().f()
}
return res
}
@@ -0,0 +1,25 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect annotation class Foo(val z: String = "OK")
// MODULE: platform()()(common)
// FILE: platform.kt
actual typealias Foo = Foo2
annotation class Foo2 (val z: String = "OK")
@Foo
fun test() {}
fun box(): String {
test()
return "OK"
}
@@ -0,0 +1,64 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: NATIVE, WASM
// IGNORE_BACKEND_K1: JVM, JVM_IR, JS, JS_IR, JS_IR_ES6
// IGNORE_BACKEND_K2: JS_IR
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect fun <T> topLevel(a: T, b: (T) -> Int = { 1 }): String
expect class Foo() {
fun <T> member(a: T, b: (T) -> Int = { 2 }): String
}
expect class Bar<T>() {
fun member(a: T, b: (T) -> Int = { 3 }): String
}
expect class A<T> {
inner class B<N> {
fun <H> foo(t: T, n: N, h: H, a: (T, N, H) -> Int = { _, _, _ -> 4 }): String
}
}
// MODULE: main()()(common)
// FILE: main.kt
import kotlin.test.assertEquals
actual fun <T> topLevel(a: T, b: (T) -> Int): String = b(a).toString()
actual class Foo actual constructor() {
actual fun <T> member(a: T, b: (T) -> Int): String = b(a).toString()
}
actual class Bar<T> actual constructor() {
actual fun member(a: T, b: (T) -> Int): String = b(a).toString()
}
actual class A<T> {
actual inner class B<N> {
actual fun <H> foo(t: T, n: N, h: H, a: (T, N, H) -> Int) = a(t, n, h).toString()
}
}
fun box(): String {
assertEquals("1", topLevel("OK"))
assertEquals("73", topLevel("OK") { 73 })
val foo = Foo()
assertEquals("2", foo.member("OK"))
assertEquals("42", foo.member("OK") { 42 })
val bar = Bar<String>()
assertEquals("3", bar.member("OK"))
assertEquals("37", bar.member("OK") { 37 })
val b = A<Int>().B<Double>()
assertEquals("4", b.foo<Int>(1, 2.0, 3))
assertEquals("6", b.foo<Int>(1, 2.0, 3) { t, n, h -> t + n.toInt() + h })
return "OK"
}