diff --git a/compiler/testData/codegen/java8/box/jvm8/bridgeInClass.kt b/compiler/testData/codegen/java8/box/jvm8/bridgeInClass.kt new file mode 100644 index 00000000000..19c3d4f5049 --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/bridgeInClass.kt @@ -0,0 +1,21 @@ +// JVM_TARGET: 1.8 + +interface Test { + fun test(p: T): T { + return p + } +} + +class TestClass : Test { + override fun test(p: String): String { + return p + "K" + } +} + +fun execute(t: Test, p: T): T { + return t.test(p) +} + +fun box(): String { + return execute(TestClass(), "O") +} diff --git a/compiler/testData/codegen/java8/box/jvm8/bridgeInInterface.kt b/compiler/testData/codegen/java8/box/jvm8/bridgeInInterface.kt new file mode 100644 index 00000000000..60ab59533fc --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/bridgeInInterface.kt @@ -0,0 +1,24 @@ +// JVM_TARGET: 1.8 + +interface Test { + fun test(p: T): T { + return p + } +} + +interface Test2: Test { + override fun test(p: String): String { + return p + "K" + } +} + +class TestClass : Test2 { +} + +fun execute(t: Test, p: T): T { + return t.test(p) +} + +fun box(): String { + return execute(TestClass(), "O") +} diff --git a/compiler/testData/codegen/java8/box/jvm8/defaultArgs.kt b/compiler/testData/codegen/java8/box/jvm8/defaultArgs.kt new file mode 100644 index 00000000000..7ece71ad052 --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/defaultArgs.kt @@ -0,0 +1,13 @@ +// JVM_TARGET: 1.8 + +interface Z { + fun test(s: String = "OK"): String { + return s + } +} + +class Test: Z + +fun box(): String { + return Test().test() +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/box/jvm8/kt11969.kt b/compiler/testData/codegen/java8/box/jvm8/kt11969.kt new file mode 100644 index 00000000000..ed1c37d439d --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/kt11969.kt @@ -0,0 +1,54 @@ +// JVM_TARGET: 1.8 +// WITH_RUNTIME +// IGNORE_BACKEND: JS + +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" +} diff --git a/compiler/testData/codegen/java8/box/jvm8/kt14243.kt b/compiler/testData/codegen/java8/box/jvm8/kt14243.kt new file mode 100644 index 00000000000..bd836e9850e --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/kt14243.kt @@ -0,0 +1,20 @@ +// JVM_TARGET: 1.8 + +interface Z { + fun test(p: T): T { + return p + } +} + +open class ZImpl : Z + +class ZImpl2 : ZImpl() { + + override fun test(p: String): String { + return super.test(p) + } +} + +fun box(): String { + return ZImpl2().test("OK") +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/box/jvm8/kt14243_2.kt b/compiler/testData/codegen/java8/box/jvm8/kt14243_2.kt new file mode 100644 index 00000000000..5983dff22dc --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/kt14243_2.kt @@ -0,0 +1,22 @@ +// JVM_TARGET: 1.8 + +interface Z { + fun test(p: T): T { + return p + } +} + +open class ZImpl : Z + +open class ZImpl2 : Z, ZImpl() + +class ZImpl3 : ZImpl2() { + + override fun test(p: String): String { + return super.test(p) + } +} + +fun box(): String { + return ZImpl3().test("OK") +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/box/jvm8/kt14243_prop.kt b/compiler/testData/codegen/java8/box/jvm8/kt14243_prop.kt new file mode 100644 index 00000000000..3053ee099b5 --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/kt14243_prop.kt @@ -0,0 +1,23 @@ +// JVM_TARGET: 1.8 + +interface Z { + val value: T + + val z: T + get() = value +} + +open class ZImpl : Z { + override val value: String + get() = "OK" +} + +open class ZImpl2 : ZImpl() { + override val z: String + get() = super.z +} + + +fun box(): String { + return ZImpl2().value +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/box/jvm8/oneImplementation.kt b/compiler/testData/codegen/java8/box/jvm8/oneImplementation.kt new file mode 100644 index 00000000000..eb3cd929267 --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/oneImplementation.kt @@ -0,0 +1,20 @@ +// JVM_TARGET: 1.8 +// KOTLIN_CONFIGURATION_FLAGS: +JVM.JVM8_TARGET_WITH_DEFAULTS +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 +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/box/jvm8/oneImplementation2.kt b/compiler/testData/codegen/java8/box/jvm8/oneImplementation2.kt new file mode 100644 index 00000000000..d589a769929 --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/oneImplementation2.kt @@ -0,0 +1,24 @@ +// 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 +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/box/jvm8/simpleCall.kt b/compiler/testData/codegen/java8/box/jvm8/simpleCall.kt new file mode 100644 index 00000000000..33575361a09 --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/simpleCall.kt @@ -0,0 +1,15 @@ +// JVM_TARGET: 1.8 + +interface Test { + fun test(): String { + return "OK" + } +} + +class TestClass : Test { + +} + +fun box(): String { + return TestClass().test() +} diff --git a/compiler/testData/codegen/java8/box/jvm8/simpleProperty.kt b/compiler/testData/codegen/java8/box/jvm8/simpleProperty.kt new file mode 100644 index 00000000000..e98f05ed57a --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/simpleProperty.kt @@ -0,0 +1,13 @@ +// JVM_TARGET: 1.8 + +interface Z { + val z: String; + get() = "OK" +} + + +class Test : Z + +fun box() : String { + return Test().z +} \ No newline at end of file diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java index 1fc180ace71..e4ba1d402d7 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java @@ -179,6 +179,72 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/box/jvm8"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("bridgeInClass.kt") + public void testBridgeInClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/bridgeInClass.kt"); + doTest(fileName); + } + + @TestMetadata("bridgeInInterface.kt") + public void testBridgeInInterface() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/bridgeInInterface.kt"); + doTest(fileName); + } + + @TestMetadata("defaultArgs.kt") + public void testDefaultArgs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/defaultArgs.kt"); + doTest(fileName); + } + + @TestMetadata("kt11969.kt") + public void testKt11969() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/kt11969.kt"); + doTest(fileName); + } + + @TestMetadata("kt14243.kt") + public void testKt14243() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/kt14243.kt"); + doTest(fileName); + } + + @TestMetadata("kt14243_2.kt") + public void testKt14243_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/kt14243_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt14243_prop.kt") + public void testKt14243_prop() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/kt14243_prop.kt"); + doTest(fileName); + } + + @TestMetadata("oneImplementation.kt") + public void testOneImplementation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/oneImplementation.kt"); + doTest(fileName); + } + + @TestMetadata("oneImplementation2.kt") + public void testOneImplementation2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/oneImplementation2.kt"); + doTest(fileName); + } + + @TestMetadata("simpleCall.kt") + public void testSimpleCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/simpleCall.kt"); + doTest(fileName); + } + + @TestMetadata("simpleProperty.kt") + public void testSimpleProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/simpleProperty.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/codegen/java8/box/jvm8/defaults") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)