Move JVM8 box test to common

This commit is contained in:
Mikhael Bogdanov
2018-10-16 11:06:27 +02:00
parent b61608aba7
commit ac8e1a0124
110 changed files with 0 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
var storage = "fail"
interface Test {
@JvmDefault
private var foo: String
get() = storage
set(value) {
storage = value
}
@JvmDefault
private fun bar(): String {
return "K"
}
@JvmDefault
fun call(): String {
return {
foo = "O"
foo + bar()
} ()
}
}
class TestClass : Test {
}
fun box(): String {
return TestClass().call()
}
@@ -0,0 +1,28 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
private val foo: String
get() = "O"
@JvmDefault
private fun bar(): String {
return "K"
}
companion object {
fun call(test: Test): String {
return test.foo + test.bar()
}
}
}
class TestClass : Test
fun box(): String {
return Test.call(TestClass())
}
@@ -0,0 +1,28 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
private val foo: String
get() = "O"
@JvmDefault
private fun bar(): String {
return "K"
}
fun call(): String {
return { foo + bar()} ()
}
}
class TestClass : Test {
}
fun box(): String {
return TestClass().call()
}
@@ -0,0 +1,26 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test<T> {
@JvmDefault
fun test(p: T): T {
return p
}
}
class TestClass : Test<String> {
override fun test(p: String): String {
return p + "K"
}
}
fun <T> execute(t: Test<T>, p: T): T {
return t.test(p)
}
fun box(): String {
return execute(TestClass(), "O")
}
@@ -0,0 +1,30 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test<T> {
@JvmDefault
fun test(p: T): T {
return p
}
}
interface Test2: Test<String> {
@JvmDefault
override fun test(p: String): String {
return p + "K"
}
}
class TestClass : Test2 {
}
fun <T> execute(t: Test<T>, p: T): T {
return t.test(p)
}
fun box(): String {
return execute(TestClass(), "O")
}
@@ -0,0 +1,68 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
interface Test<T> {
@JvmDefault
fun test(p: T): T {
return null!!
}
fun foo(p: T): T {
return null!!
}
}
interface Test2: Test<String> {
@JvmDefault
override fun test(p: String): String {
return p
}
override fun foo(p: String): String {
return p
}
}
class TestClass : Test2
fun box(): String {
checkNoMethod(Test2::class.java, "foo", Any::class.java)
checkMethodExists(Test2::class.java, "test", Any::class.java)
checkNoMethod(TestClass::class.java, "test", Any::class.java)
checkMethodExists(TestClass::class.java, "foo", String::class.java)
checkMethodExists(TestClass::class.java, "foo", Any::class.java)
val test2DefaultImpls = java.lang.Class.forName("Test2\$DefaultImpls")
checkNoMethod(test2DefaultImpls, "test", Any::class.java)
checkNoMethod(test2DefaultImpls, "test", String::class.java)
checkMethodExists(test2DefaultImpls, "foo", Test2::class.java, String::class.java)
return "OK"
}
fun checkNoMethod(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) {
try {
clazz.getDeclaredMethod(name, *parameterTypes)
}
catch (e: NoSuchMethodException) {
return
}
throw AssertionError("fail: method $name was found in " + clazz)
}
fun checkMethodExists(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) {
try {
clazz.getDeclaredMethod(name, *parameterTypes)
return
}
catch (e: NoSuchMethodException) {
throw AssertionError("fail: method $name was not found in " + clazz, e)
}
}
@@ -0,0 +1,35 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test<T> {
@JvmDefault
var test: T
get() = null!!
set(value) {
null!!
}
}
var result = "fail"
interface Test2 : Test<String> {
@JvmDefault
override var test: String
get() = result
set(value) {
result = value
}
}
class TestClass : Test2
fun <T> execute(t: Test<T>, p: T): T {
t.test = p
return t.test
}
fun box(): String {
return execute(TestClass(), "OK")
}
@@ -0,0 +1,82 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
interface Test<T> {
@JvmDefault
var T.test: T
get() = null!!
set(value) {
null!!
}
var T.foo: T
get() = null!!
set(value) {
null!!
}
}
interface Test2 : Test<String> {
@JvmDefault
override var String.test: String
get() = ""
set(value) {}
override var String.foo: String
get() = ""
set(value) {}
}
class TestClass : Test2
fun box(): String {
checkMethodExists(Test2::class.java, "getTest", String::class.java)
checkMethodExists(Test2::class.java, "getTest", Any::class.java)
checkMethodExists(Test2::class.java, "setTest", Any::class.java, Any::class.java)
checkMethodExists(Test2::class.java, "setTest", String::class.java, String::class.java)
checkNoMethod(Test2::class.java, "setFoo", Any::class.java, Any::class.java)
checkNoMethod(TestClass::class.java, "getTest", String::class.java)
checkNoMethod(TestClass::class.java, "getTest", Any::class.java)
checkNoMethod(TestClass::class.java, "setTest", Any::class.java, Any::class.java)
checkNoMethod(TestClass::class.java, "setTest", String::class.java, String::class.java)
checkMethodExists(TestClass::class.java, "getFoo", String::class.java)
checkMethodExists(TestClass::class.java, "getFoo", Any::class.java)
checkMethodExists(TestClass::class.java, "setFoo", Any::class.java, Any::class.java)
checkMethodExists(TestClass::class.java, "setFoo", String::class.java, String::class.java)
val test2DefaultImpls = java.lang.Class.forName("Test2\$DefaultImpls")
checkNoMethod(test2DefaultImpls, "getTest", String::class.java)
checkNoMethod(test2DefaultImpls, "getTest", Any::class.java)
checkNoMethod(test2DefaultImpls, "setTest", Any::class.java, Any::class.java)
checkNoMethod(test2DefaultImpls, "setTest", String::class.java, String::class.java)
return "OK"
}
fun checkNoMethod(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) {
try {
clazz.getDeclaredMethod(name, *parameterTypes)
}
catch (e: NoSuchMethodException) {
return
}
throw AssertionError("fail: method $name was found in " + clazz)
}
fun checkMethodExists(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) {
try {
clazz.getDeclaredMethod(name, *parameterTypes)
return
}
catch (e: NoSuchMethodException) {
throw AssertionError("fail: method $name was not found in " + clazz, e)
}
}
@@ -0,0 +1,60 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
// FILE: Test.java
public interface Test<T> {
default T test(T p) {
return null;
}
}
// FILE: kotlin.kt
interface Test2: Test<String> {
@JvmDefault
override fun test(p: String): String {
return p
}
fun forDefaultImpls() {}
}
class TestClass : Test2
fun box(): String {
checkMethodExists(Test2::class.java, "test", String::class.java)
checkMethodExists(Test2::class.java, "test", Any::class.java)
checkNoMethod(TestClass::class.java, "test", String::class.java)
checkNoMethod(TestClass::class.java, "test", Any::class.java)
val test2DefaultImpls = java.lang.Class.forName("Test2\$DefaultImpls")
checkNoMethod(test2DefaultImpls, "test", Any::class.java)
checkNoMethod(test2DefaultImpls, "test", String::class.java)
return "OK"
}
fun checkNoMethod(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) {
try {
clazz.getDeclaredMethod(name, *parameterTypes)
}
catch (e: NoSuchMethodException) {
return
}
throw AssertionError("fail: method $name was found in " + clazz)
}
fun checkMethodExists(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) {
try {
clazz.getDeclaredMethod(name, *parameterTypes)
return
}
catch (e: NoSuchMethodException) {
throw AssertionError("fail: method $name was not found in " + clazz, e)
}
}
@@ -0,0 +1,26 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
fun foo(): String = "O"
@JvmDefault
val bar: String
get() = "K"
fun test(): String {
return (::foo)() + (::bar)()
}
}
class TestClass : Test {
}
fun box(): String {
return TestClass().test()
}
@@ -0,0 +1,30 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface IBase {
@JvmDefault
fun bar() = "OK"
}
open class Base {
fun foo() = "OK"
}
class C : Base(), IBase {
val lambda1 = {
super.foo()
}
val lambda2 = {
super.bar()
}
}
fun box(): String {
if (C().lambda1() != "OK") return "fail 1"
return C().lambda2()
}
@@ -0,0 +1,39 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: 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 {
}
// FILE: main.kt
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KInterface<T> {
@JvmDefault
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,37 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: 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> {
@JvmDefault
fun test2(p: T): T {
return p
}
}
interface KInterface2 : KInterface<String> {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,41 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: 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> {
@JvmDefault
fun test2(p: T): T {
return p
}
}
interface KInterface2 : KInterface<String> {
}
interface KInterface3 : KInterface2 {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,44 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: compatibility
// 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
@JvmDefault
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
@JvmDefault
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,41 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: compatibility
// 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
@JvmDefault
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
@JvmDefault
override val foo: String
get() = "OK"
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,43 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: compatibility
// 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
@JvmDefault
val bar: T
get() = foo
}
interface KInterface2 : KInterface<String> {
@JvmDefault
override val foo: String
get() = "OK"
}
interface KInterface3 : KInterface2 {
}
fun box(): String {
return Foo().test()
}
@@ -0,0 +1,23 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
interface Test {
@JvmDefault
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,38 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: compatibility
// 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 {
@JvmDefault
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,25 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: compatibility
// 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")
@JvmDefault
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,34 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: compatibility
// 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 {
@JvmDefault
fun test2(): String {
return "OK"
}
}
fun box(): String {
val result = Foo().test()
if (result != "OK") return "fail 1: ${result}"
return Foo().test2()
}
@@ -0,0 +1,17 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Z {
@JvmDefault
fun test(s: String = "OK"): String {
return s
}
}
class Test: Z
fun box(): String {
return Test().test()
}
@@ -0,0 +1,33 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
fun test(): String {
return "O"
}
fun delegatedTest(): String {
return "fail"
}
}
class Delegate : Test {
override fun test(): String {
return "Fail"
}
override fun delegatedTest(): String {
return "K"
}
}
class TestClass(val foo: Test) : Test by foo
fun box(): String {
val testClass = TestClass(Delegate())
return testClass.test() + testClass.delegatedTest()
}
@@ -0,0 +1,30 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
val test: String
get() = "O"
val testDelegated: String
get() = "fail"
}
class Delegate : Test {
override val test: String
get() = "fail"
override val testDelegated: String
get() = "K"
}
class TestClass(val foo: Test) : Test by foo
fun box(): String {
val testClass = TestClass(Delegate())
return testClass.test + testClass.testDelegated
}
+54
View File
@@ -0,0 +1,54 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_REFLECT
// FULL_JDK
interface Test {
@JvmDefault
fun test(): String {
return "Test"
}
}
open class TestClass : Test {
}
interface Test2 : Test {
@JvmDefault
override fun test(): String {
return "Test2"
}
}
interface Test3 : Test2 {
}
class TestClass2 : TestClass(), Test3 {
}
fun box(): String {
val test = TestClass2().test()
if (test != "Test2") return "fail 1: $test"
checkNoMethod(TestClass::class.java, "test")
checkNoMethod(Test3::class.java, "test")
checkNoMethod(TestClass2::class.java, "test")
return "OK"
}
fun checkNoMethod(clazz: Class<*>, name: String) {
try {
clazz.getDeclaredMethod(name)
}
catch (e: NoSuchMethodException) {
return
}
throw AssertionError("fail " + clazz)
}
+29
View File
@@ -0,0 +1,29 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
fun test(): String {
return inlineFun { "O" }
}
fun testDefaultImpls(): String {
return inlineFun { "K" }
}
@JvmDefault
private inline fun inlineFun(s: () -> String) = s()
}
class TestClass : Test {
}
fun box(): String {
val foo = TestClass()
return foo.test() + foo.testDefaultImpls()
}
@@ -0,0 +1,31 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
fun test(): String {
return inlineProp
}
fun testDefaultImpls(): String {
return inlineProp
}
@JvmDefault
private inline val inlineProp: String
get() = "OK"
}
class TestClass : Test {
}
fun box(): String {
val foo = TestClass()
if (foo.test() != "OK") return "fail: ${foo.test()}"
return foo.testDefaultImpls()
}
+62
View File
@@ -0,0 +1,62 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Z {
@JvmDefault
private fun privateFun() = { "OK" }
@JvmDefault
fun callPrivateFun() = privateFun()
@JvmDefault
fun publicFun() = { "OK" }
@JvmDefault
fun funWithDefaultArgs(s: () -> Unit = {}): () -> Unit
@JvmDefault
val property: () -> Unit
get() = {}
class Nested
}
class Test : Z {
override fun funWithDefaultArgs(s: () -> Unit): () -> Unit {
return s
}
}
fun box(): String {
val privateFun = Test().callPrivateFun()
var enclosing = privateFun.javaClass.enclosingMethod!!
if (enclosing.name != "privateFun") return "fail 1: ${enclosing.name}"
if (enclosing.getDeclaringClass().simpleName != "Z") return "fail 2: ${enclosing.getDeclaringClass().simpleName}"
val publicFun = Test().publicFun()
enclosing = publicFun.javaClass.enclosingMethod!!
if (enclosing.name != "publicFun") return "fail 3: ${enclosing.name}"
if (enclosing.getDeclaringClass().simpleName != "Z") return "fail 4: ${enclosing.getDeclaringClass().simpleName}"
val property = Test().property
enclosing = property.javaClass.enclosingMethod!!
if (enclosing.name != "getProperty") return "fail 4: ${enclosing.name}"
if (enclosing.getDeclaringClass().simpleName != "Z") return "fail 5: ${enclosing.getDeclaringClass().simpleName}"
val defaultArgs = Test().funWithDefaultArgs()
enclosing = defaultArgs.javaClass.enclosingMethod!!
if (enclosing.name != "funWithDefaultArgs\$default") return "fail 6: ${enclosing.name}"
if (enclosing.parameterTypes.size != 4) return "fail 7: not default method ${enclosing.name}"
if (enclosing.getDeclaringClass().simpleName != "Z") return "fail 8: ${enclosing.getDeclaringClass().simpleName}"
val nested = Z.Nested::class.java
val enclosingClass = nested.enclosingClass!!
if (enclosingClass.name != "Z") return "fail 9: ${enclosingClass.name}"
return "OK"
}
+25
View File
@@ -0,0 +1,25 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Z<T> {
@JvmDefault
fun test(p: T): T {
return p
}
}
open class ZImpl : Z<String>
class ZImpl2 : ZImpl() {
override fun test(p: String): String {
return super.test(p)
}
}
fun box(): String {
return ZImpl2().test("OK")
}
@@ -0,0 +1,27 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Z<T> {
@JvmDefault
fun test(p: T): T {
return p
}
}
open class ZImpl : Z<String>
open class ZImpl2 : Z<String>, ZImpl()
class ZImpl3 : ZImpl2() {
override fun test(p: String): String {
return super.test(p)
}
}
fun box(): String {
return ZImpl3().test("OK")
}
@@ -0,0 +1,29 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Z<T> {
val value: T
@JvmDefault
val z: T
get() = value
}
open class ZImpl : Z<String> {
override val value: String
get() = "OK"
}
open class ZImpl2 : ZImpl() {
override val z: String
get() = super.z
}
fun box(): String {
return ZImpl2().value
}
@@ -0,0 +1,26 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
interface Test {
@JvmDefault
fun test() {
}
}
class TestClass : Test {
}
fun box(): String {
try {
TestClass::class.java.getDeclaredMethod("test")
}
catch (e: NoSuchMethodException) {
return "OK"
}
return "fail"
}
@@ -0,0 +1,26 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
interface Test {
@JvmDefault
fun test() {
}
}
interface Test2 : Test {
}
fun box(): String {
try {
Test2::class.java.getDeclaredMethod("test")
}
catch (e: NoSuchMethodException) {
return "OK"
}
return "fail"
}
@@ -0,0 +1,30 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
// FULL_JDK
interface Test {
@JvmDefault
fun test() {
}
}
interface Test2 : Test {
}
interface Test3 : Test2 {
}
fun box(): String {
try {
Test3::class.java.getDeclaredMethod("test")
}
catch (e: NoSuchMethodException) {
return "OK"
}
return "fail"
}
@@ -0,0 +1,26 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KCallable {
@JvmDefault
val returnType: String
}
interface KCallableImpl : KCallable {
@JvmDefault
override val returnType: String
get() = "OK"
}
interface KCallableImpl2 : KCallableImpl
open class DescriptorBasedProperty : KCallableImpl
open class KProperty1Impl : DescriptorBasedProperty(), KCallableImpl2
open class KMutableProperty1Impl : KProperty1Impl(), KCallable
fun box(): String {
return KMutableProperty1Impl().returnType
}
@@ -0,0 +1,31 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface KCallable {
@JvmDefault
val returnType: String
}
interface KCallableImpl : KCallable {
@JvmDefault
override val returnType: String
get() = "OK"
}
interface KProperty : KCallable
interface KPropertyImpl : KProperty, KCallableImpl
interface KMutableProperty : KProperty
interface KProperty1 : KProperty
interface KMutableProperty1 : KProperty1, KMutableProperty
interface KMutablePropertyImpl : KPropertyImpl
open class DescriptorBasedProperty : KCallableImpl
open class KProperty1Impl : DescriptorBasedProperty(), KProperty1, KPropertyImpl
open class KMutableProperty1Impl : KProperty1Impl(), KMutableProperty1, KMutablePropertyImpl
fun box(): String {
return KMutableProperty1Impl().returnType
}
@@ -0,0 +1,26 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
fun test(): String {
return privateFun() + privateProp
}
@JvmDefault
private fun privateFun(): String {
return "O"
}
@JvmDefault
private val privateProp: String
get() = "K"
}
class TestImpl: Test
fun box(): String {
return TestImpl().test()
}
@@ -0,0 +1,25 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
fun test(): String {
return privateFun() + privateProp
}
private fun privateFun(): String {
return "O"
}
private val privateProp: String
get() = "K"
}
class TestImpl: Test
fun box(): String {
return TestImpl().test()
}
@@ -0,0 +1,25 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// 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")
@JvmDefault
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,20 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
fun test(): String {
return "OK"
}
}
class TestClass : Test {
}
fun box(): String {
return TestClass().test()
}
@@ -0,0 +1,18 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Z {
@JvmDefault
val z: String
get() = "OK"
}
class Test : Z
fun box() : String {
return Test().z
}
@@ -0,0 +1,29 @@
// !API_VERSION: 1.3
// !JVM_DEFAULT_MODE: enable
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Test {
@JvmDefault
fun test(): String {
return "OK"
}
}
interface Test2 : Test {
@JvmDefault
override fun test(): String {
return super.test()
}
}
class TestClass : Test2 {
}
fun box(): String {
return TestClass().test()
}