Add new tests

This commit is contained in:
Mikhael Bogdanov
2020-02-04 10:57:33 +01:00
committed by Mikhail Bogdanov
parent 0570c05683
commit 0c0bd67a6b
50 changed files with 1959 additions and 1 deletions
@@ -0,0 +1,38 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return KInterface2.DefaultImpls.test2(this, "OK");
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
fun test2(p: T): T {
return p
}
}
interface KInterface2 : KInterface<String> {
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().test2("OK")
}
@@ -0,0 +1,35 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return KInterface2.DefaultImpls.test2(this, "OK");
}
}
// FILE: Foo.java
public class Foo implements Simple {
public String test2(String p) {
return "fail";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
fun test2(p: T): T {
return p
}
}
interface KInterface2 : KInterface<String> {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,39 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface3 {
default String test() {
return KInterface3.DefaultImpls.test2(this, "OK");
}
}
// FILE: Foo.java
public class Foo implements Simple {
public String test2(String p) {
return "fail";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
fun test2(p: T): T {
return p
}
}
interface KInterface2 : KInterface<String> {
}
interface KInterface3 : KInterface2 {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,42 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return KInterface2.DefaultImpls.getBar(this);
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
val foo: T
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
override val foo: String
get() = "OK"
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().bar
}
@@ -0,0 +1,39 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return KInterface2.DefaultImpls.getBar(this);
}
}
// FILE: Foo.java
public class Foo implements Simple {
public String getBar() {
return "fail";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
val foo: T
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
override val foo: String
get() = "OK"
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,41 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface3 {
default String test() {
return KInterface3.DefaultImpls.getBar(this);
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
val foo: T
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
override val foo: String
get() = "OK"
}
interface KInterface3 : KInterface2 {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,43 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FULL_JDK
// WITH_RUNTIME
// FILE: Simple.java
public interface Simple extends KInterface {
default java.util.List<String> compatibilityCall() {
return KInterface.DefaultImpls.call(this);
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface {
fun call(): List<String> {
return Thread.currentThread().getStackTrace().map { it.className + "." + it.methodName }
}
}
fun box(): String {
var result = Foo().compatibilityCall()
if (result[1] != "KInterface.call") return "fail 1: ${result[1]}"
if (result[2] != "KInterface.access\$call\$jd") return "fail 2: ${result[2]}"
if (result[3] != "KInterface\$DefaultImpls.call") return "fail 3: ${result[3]}"
if (result[4] != "Simple.compatibilityCall") return "fail 4: ${result[4]}"
if (result[5] != "MainKt.box") return "fail 5: ${result[5]}"
result = Foo().call()
if (result[1] != "KInterface.call") return "fail 1: ${result[1]}"
if (result[2] != "MainKt.box") return "fail 2: ${result[2]}"
return "OK"
}
@@ -0,0 +1,23 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
interface Test {
fun test(s: String ="OK"): String {
return s
}
}
class TestClass : Test {
}
fun box(): String {
val defaultImpls = java.lang.Class.forName(Test::class.java.canonicalName + "\$DefaultImpls")
val declaredMethod = defaultImpls.getDeclaredMethod("test\$default", Test::class.java, String::class.java, Int::class.java, Any::class.java)
return declaredMethod.invoke(null, TestClass(), null, 1, null) as String
}
@@ -0,0 +1,16 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface A {
fun foo(x: String = "OK"): String {
return x
}
}
fun box(): String {
val x = object : A {}
return x.foo()
}
@@ -0,0 +1,12 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface I {
fun foo(x: String = "OK"): String = x
}
interface J : I
object O : J
fun box(): String = O.foo()
@@ -0,0 +1,37 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return KInterface2.DefaultImpls.test2(this);
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface {
fun test2(): String {
return "OK"
}
}
interface KInterface2 : KInterface {
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().test2()
}
@@ -0,0 +1,13 @@
// IGNORE_BACKEND_FIR: JVM_IR
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface A {
fun String.foo(k: String) = "O" + k
}
fun box(): String =
object : A {
fun box() = "FAIL".foo("K")
}.box()
@@ -0,0 +1,24 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_REFLECT
annotation class Property(val value: String)
annotation class Accessor(val value: String)
interface Z {
@Property("OK")
val z: String
@Accessor("OK")
get() = "OK"
}
class Test : Z
fun box() : String {
val value = Z::z.annotations.filterIsInstance<Property>().single().value
if (value != "OK") return value
return (Z::z.getter.annotations.single() as Accessor).value
}
@@ -0,0 +1,33 @@
// !JVM_DEFAULT_MODE: all-compatibility
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface {
default String test() {
return KInterface.DefaultImpls.test2(this);
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface {
fun test2(): String {
return "OK"
}
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().test2()
}
@@ -1,7 +1,9 @@
// !JVM_DEFAULT_MODE: compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface I {
@JvmDefault
fun foo(x: String = "OK"): String = x
}
@@ -0,0 +1,38 @@
// !JVM_DEFAULT_MODE: all
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return KInterface2.super.test2("OK");
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
fun test2(p: T): T {
return p
}
}
interface KInterface2 : KInterface<String> {
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().test2("OK")
}
@@ -0,0 +1,35 @@
// !JVM_DEFAULT_MODE: all
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return KInterface2.super.test2("OK");
}
}
// FILE: Foo.java
public class Foo implements Simple {
public String test2(String p) {
return "fail";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
fun test2(p: T): T {
return p
}
}
interface KInterface2 : KInterface<String> {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,39 @@
// !JVM_DEFAULT_MODE: all
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface3 {
default String test() {
return KInterface3.super.test2("OK");
}
}
// FILE: Foo.java
public class Foo implements Simple {
public String test2(String p) {
return "fail";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
fun test2(p: T): T {
return p
}
}
interface KInterface2 : KInterface<String> {
}
interface KInterface3 : KInterface2 {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,42 @@
// !JVM_DEFAULT_MODE: all
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return getBar();
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
val foo: T
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
override val foo: String
get() = "OK"
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().bar
}
@@ -0,0 +1,39 @@
// !JVM_DEFAULT_MODE: all
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return KInterface2.super.getBar();
}
}
// FILE: Foo.java
public class Foo implements Simple {
public String getBar() {
return "fail";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
val foo: T
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
override val foo: String
get() = "OK"
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,41 @@
// !JVM_DEFAULT_MODE: all
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface3 {
default String test() {
return getBar();
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
val foo: T
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
override val foo: String
get() = "OK"
}
interface KInterface3 : KInterface2 {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,24 @@
// !JVM_DEFAULT_MODE: all
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
interface Test {
fun test(s: String ="OK"): String {
return s
}
}
class TestClass : Test {
}
fun box(): String {
try {
val defaultImpls = java.lang.Class.forName(Test::class.java.canonicalName + "\$DefaultImpls")
} catch (e: ClassNotFoundException) {
return "OK"
}
return "fail: DefaultImpls shouldn't be generated"
}
@@ -0,0 +1,16 @@
// !JVM_DEFAULT_MODE: all
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface A {
fun foo(x: String = "OK"): String {
return x
}
}
fun box(): String {
val x = object : A {}
return x.foo()
}
@@ -0,0 +1,12 @@
// !JVM_DEFAULT_MODE: all
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface I {
fun foo(x: String = "OK"): String = x
}
interface J : I
object O : J
fun box(): String = O.foo()
@@ -0,0 +1,37 @@
// !JVM_DEFAULT_MODE: all
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface2 {
default String test() {
return test2();
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface {
fun test2(): String {
return "OK"
}
}
interface KInterface2 : KInterface {
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().test2()
}
@@ -0,0 +1,13 @@
// IGNORE_BACKEND_FIR: JVM_IR
// !JVM_DEFAULT_MODE: all
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface A {
fun String.foo(k: String) = "O" + k
}
fun box(): String =
object : A {
fun box() = "FAIL".foo("K")
}.box()
@@ -0,0 +1,24 @@
// !JVM_DEFAULT_MODE: all
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_REFLECT
annotation class Property(val value: String)
annotation class Accessor(val value: String)
interface Z {
@Property("OK")
val z: String
@Accessor("OK")
get() = "OK"
}
class Test : Z
fun box() : String {
val value = Z::z.annotations.filterIsInstance<Property>().single().value
if (value != "OK") return value
return (Z::z.getter.annotations.single() as Accessor).value
}
@@ -0,0 +1,33 @@
// !JVM_DEFAULT_MODE: all
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple extends KInterface {
default String test() {
return test2();
}
}
// FILE: Foo.java
public class Foo implements Simple {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface {
fun test2(): String {
return "OK"
}
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().test2()
}