[FIR] Update backend tests with actual/expect in same module

- The fix for KT-55570 caused some backend tests to fail, because errors
  are now correctly reported for simple classes and actual/expect in
  the same module is not supported in FIR. See KT-55177.
- The commit also adds separate tests for K2. Unfortunately, these have
  to be disabled for K1 because K1 then reports "expect without actual"
  errors.
This commit is contained in:
Marco Pennekamp
2023-01-27 20:08:13 +01:00
committed by teamcity
parent d6cb75ca91
commit 9a693fa967
28 changed files with 333 additions and 70 deletions
@@ -1,5 +1,8 @@
// IGNORE_BACKEND: NATIVE
// !LANGUAGE: +MultiPlatformProjects
// 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).
// MODULE: lib
// FILE: impl.kt
class A(val result: String = "OK")
@@ -0,0 +1,20 @@
// IGNORE_BACKEND: NATIVE
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K1: ANY
// IGNORE_BACKEND_MULTI_MODULE: ANY
// MODULE: lib1
// FILE: impl.kt
class A(val result: String = "OK")
// MODULE: lib2
// FILE: B.kt
expect class B(result: String = "FAIL")
// MODULE: main(lib1)()(lib2)
// FILE: multiplatform.kt
actual typealias B = A
fun box(): String {
return B().result
}
@@ -1,6 +1,8 @@
// TARGET_BACKEND: JVM
// !LANGUAGE: +MultiPlatformProjects
// WITH_REFLECT
// 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).
// MODULE: lib
// FILE: Jnno.java
@@ -0,0 +1,99 @@
// TARGET_BACKEND: JVM
// !LANGUAGE: +MultiPlatformProjects
// WITH_REFLECT
// IGNORE_BACKEND_K1: ANY
// MODULE: lib1
// 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")};
}
// MODULE: lib2
// FILE: Anno.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")]
)
// enum class E { E1, E2, E3 }
annotation class A(val value: String)
@Anno
fun test() {}
// MODULE: main(lib1)()(lib2)
// FILE: main.kt
actual typealias Anno = Jnno
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"
}
@@ -1,5 +1,8 @@
// !LANGUAGE: +MultiPlatformProjects
// 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
expect annotation class Foo(val z: String = "OK")
@@ -0,0 +1,23 @@
// !LANGUAGE: +MultiPlatformProjects
// WITH_STDLIB
// IGNORE_BACKEND_K1: ANY
// IGNORE_BACKEND_K2: JS_IR, NATIVE
// MODULE: common
// FILE: common.kt
expect annotation class Foo(val z: String = "OK")
// MODULE: main()()(common)
// FILE: main.kt
actual typealias Foo = Foo2
annotation class Foo2 (val z: String = "OK")
@Foo
fun test() {}
fun box(): String {
test()
return "OK"
}