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
+22
View File
@@ -0,0 +1,22 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Test<T> {
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")
}
+25
View File
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Test<T> {
fun test(p: T): T {
return p
}
}
interface Test2: Test<String> {
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")
}
+30
View File
@@ -0,0 +1,30 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// FILE: IBase.java
interface IBase {
default String bar() {
return "OK";
}
}
// FILE: Kotlin.kt
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()
}
+14
View File
@@ -0,0 +1,14 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Z {
fun test(s: String = "OK"): String {
return s
}
}
class Test: Z
fun box(): String {
return Test().test()
}
+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()
}
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
//WITH_RUNTIME
// FILE: 1.kt
package test
public inline fun <T, R> Iterable<T>.fold2(initial: R, operation: (R, T) -> R): R {
var accumulator = initial
for (element in this) accumulator = operation(accumulator, element)
return accumulator
}
// FILE: 2.kt
import test.*
fun box(): String {
val list = listOf("O", "K")
return list.fold2("") {a, b -> a +b}
}
@@ -0,0 +1,9 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
//WITH_RUNTIME
fun box(): String {
val list = listOf("O", "K")
return list.fold("") {a, b -> a +b}
}
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple {
default String test() {
return "O";
}
static String testStatic() {
return "K";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
class TestClass : Simple {
override fun test(): String {
return super.test()
}
}
fun box(): String {
return TestClass().test() + Simple.testStatic()
}
@@ -0,0 +1,27 @@
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple {
default String test() {
return "O";
}
static String testStatic() {
return "K";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
interface KSimple : Simple {}
class TestClass : KSimple {
override fun test(): String {
return super.test()
}
}
fun box(): String {
return TestClass().test() + Simple.testStatic()
}
@@ -0,0 +1,30 @@
// TARGET_BACKEND: JVM
// FILE: IBase.java
interface IBase {
default String bar() {
return "OK";
}
}
// FILE: Kotlin.kt
// JVM_TARGET: 1.8
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,29 @@
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple {
default String test(String s) {
return s + "K";
}
static String testStatic(String s) {
return s + "K";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
interface KInterface : Simple {
fun bar(): String {
return test("O") + Simple.testStatic("O")
}
}
class Test : KInterface {}
fun box(): String {
val test = Test().bar()
if (test != "OKOK") return "fail $test"
return "OK"
}
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// FILE: Simple.java
interface Simple {
default String test(String s) {
return s + "K";
}
static String testStatic(String s) {
return s + "K";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
class Test : Simple {}
fun box(): String {
val test = Test().test("O")
if (test != "OK") return "fail $test"
return Simple.testStatic("O")
}
@@ -0,0 +1,24 @@
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple {
default String test(String s) {
return s + "K";
}
static String testStatic(String s) {
return s + "K";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
interface TestInterface : Simple {}
class Test : TestInterface {}
fun box(): String {
val test = Test().test("O")
if (test != "OK") return "fail $test"
return Simple.testStatic("O")
}
@@ -0,0 +1,24 @@
// TARGET_BACKEND: JVM
// FILE: Simple.java
public interface Simple {
default String test(String s) {
return s + "Fail";
}
}
// FILE: main.kt
interface KInterface: Simple {
override fun test(s: String): String {
return s + "K"
}
}
class Test : KInterface {
}
fun box(): String {
return Test().test("O")
}
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM
// FILE: Test.java
interface Test<T> {
T call();
default T testDefault(T p) {
return p;
}
}
// FILE: main.kt
class Child : Test<String> {
override fun call() : String {
return "OK"
}
}
fun box(): String {
val res = Child().call()
if (res != "OK") return "fail $res"
return Child().testDefault("OK")
}
@@ -0,0 +1,32 @@
// TARGET_BACKEND: JVM
// FILE: Simple.java
interface Simple extends KInterface {
default String test() {
return "simple";
}
}
// FILE: main.kt
// JVM_TARGET: 1.8
interface KInterface {
fun test(): String {
return "base";
}
}
class Test : Simple {
fun bar(): String {
return super.test()
}
}
fun box(): String {
val test = Test().test()
if (test != "simple") return "fail $test"
val bar = Test().bar()
if (bar != "simple") return "fail 2 $bar"
return "OK"
}
@@ -0,0 +1,43 @@
// TARGET_BACKEND: JVM
// FILE: Test.java
public interface Test {
default String test() {
return "OK";
}
}
// FILE: test.kt
// JVM_TARGET: 1.8
interface KInterface : Test {
}
class KClass : Test {
fun ktest(): String {
return super.test() + test()
}
}
class KTClass : KInterface {
fun ktest(): String {
return super.test() + test()
}
}
fun box(): String {
val p = object : KInterface {
fun ktest(): String {
return super.test() + test()
}
}.ktest()
if (p != "OKOK") return "fail1: $p"
if (KClass().ktest() != "OKOK") return "fail 2: ${KClass().ktest()}"
if (KTClass().ktest() != "OKOK") return "fail 3: ${KTClass().ktest()}"
return "OK"
}
@@ -0,0 +1,46 @@
// TARGET_BACKEND: JVM
// FILE: Test.java
public interface Test {
default String test() {
return "OK";
}
}
// FILE: test.kt
interface KInterface : Test {
}
class KClass : Test {
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR")
fun ktest(): String {
return super.test() + test()
}
}
class KTClass : KInterface {
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR")
fun ktest(): String {
return super.test() + test()
}
}
fun box(): String {
val p = object : KInterface {
@kotlin.Suppress("DEFAULT_METHOD_CALL_FROM_JAVA6_TARGET_ERROR")
fun ktest(): String {
return super.test() + test()
}
}.ktest()
if (p != "OKOK") return "fail1: $p"
if (KClass().ktest() != "OKOK") return "fail 2: ${KClass().ktest()}"
if (KTClass().ktest() != "OKOK") return "fail 3: ${KTClass().ktest()}"
return "OK"
}
@@ -0,0 +1,22 @@
// TARGET_BACKEND: JVM
// FILE: Base.java
public interface Base {
default String foo() {
return "OK";
}
}
// FILE: derived.kt
// JVM_TARGET: 1.8
interface K1 : Base
interface K2 : K1
interface K3 : K2
class C : K3 {
override fun foo() = super.foo()
}
fun box(): String = C().foo()
@@ -0,0 +1,29 @@
// TARGET_BACKEND: JVM
// FILE: JavaCall.java
class JavaCall {
String call(Test test) {
return test.call();
}
}
// FILE: Test.java
interface Test {
String call();
default String test() {
return "K";
}
static String testStatic() {
return "K";
}
}
// FILE: sam.kt
fun box(): String {
return JavaCall().call {"OK"}
}
+54
View File
@@ -0,0 +1,54 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_RUNTIME
interface Z {
private fun privateFun() = { "OK" }
fun callPrivateFun() = privateFun()
fun publicFun() = { "OK" }
fun funWithDefaultArgs(s: () -> Unit = {}): () -> Unit
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 != "DefaultImpls") 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 != "DefaultImpls") 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 != "DefaultImpls") 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 != "DefaultImpls") 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"
}
+21
View File
@@ -0,0 +1,21 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Z<T> {
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")
}
+23
View File
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Z<T> {
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")
}
+24
View File
@@ -0,0 +1,24 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Z<T> {
val value: T
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
}
+10
View File
@@ -0,0 +1,10 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
fun failAtRuntime(numberArg: Number = 0.0): Number {
return numberArg
}
fun box(): String {
failAtRuntime()
return "OK"
}
+18
View File
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
fun test(o: Number) {}
fun test2(o: Number) {
val p: Int = 1
val o = if (z < 1) p else o
test(o)
}
var z = 1
fun box(): String {
val x: Number = 1
test2(x)
return "OK"
}
+13
View File
@@ -0,0 +1,13 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
fun number(doLong: Boolean): Number = when {
doLong -> 1.toLong()
else -> 0
}
fun box(): String {
number(true)
return "OK"
}
+27
View File
@@ -0,0 +1,27 @@
// !LANGUAGE: +JvmStaticInInterface
// WITH_RUNTIME
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// FILE: test.kt
fun box(): String {
return Java.test()
}
interface Foo {
companion object {
@JvmStatic
fun foo() = "O"
@JvmStatic
var fooProp = ""
}
}
// FILE: Java.java
public class Java {
public static String test() {
Foo.setFooProp("K");
return Foo.foo() + Foo.getFooProp();
}
}
+27
View File
@@ -0,0 +1,27 @@
// !LANGUAGE: +JvmStaticInInterface
// WITH_RUNTIME
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// FILE: test.kt
fun box(): String {
return Java.test()
}
interface Foo {
companion object {
@JvmStatic
fun foo() = "O"
val fooProp = "K"
@JvmStatic get
}
}
// FILE: Java.java
public class Java {
public static String test() {
return Foo.foo() + Foo.getFooProp();
}
}
+20
View File
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface KCallable {
val returnType: String
}
interface KCallableImpl : KCallable {
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,25 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface KCallable {
val returnType: String
}
interface KCallableImpl : KCallable {
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
}
+16
View File
@@ -0,0 +1,16 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Test {
fun test(): String {
return "OK"
}
}
class TestClass : Test {
}
fun box(): String {
return TestClass().test()
}
+14
View File
@@ -0,0 +1,14 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Z {
val z: String
get() = "OK"
}
class Test : Z
fun box() : String {
return Test().z
}