From ad717d5335c1716d648573d247d1980cb62e5a67 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Tue, 29 May 2018 14:36:30 +0200 Subject: [PATCH] Support properties in compatibility mode --- .../kotlin/codegen/MemberCodegen.java | 17 ++++++++ .../compatibility/bridgeWithProperties.kt | 43 +++++++++++++++++++ .../compatibility/bridgeWithProperties2.kt | 40 +++++++++++++++++ .../compatibility/bridgeWithProperties3.kt | 42 ++++++++++++++++++ .../compatibility/simpleProperty.kt | 26 +++++++++++ ...BlackBoxWithJava8CodegenTestGenerated.java | 15 +++++++ .../BytecodeTextJava8TestGenerated.java | 5 +++ 7 files changed, 188 insertions(+) create mode 100644 compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties.kt create mode 100644 compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties2.kt create mode 100644 compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties3.kt create mode 100644 compiler/testData/codegen/java8/bytecodeText/jvmDefault/compatibility/simpleProperty.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index 65a224a0712..92b3041f1b6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -757,6 +757,23 @@ public abstract class MemberCodegen { + + val foo: T + + @JvmDefault + val bar: T + get() = foo +} + +interface KInterface2 : KInterface { + @JvmDefault + override val foo: String + get() = "OK" +} + + +fun box(): String { + + val result = Foo().test() + if (result != "OK") return "fail 1: ${result}" + + return Foo().bar + +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties2.kt b/compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties2.kt new file mode 100644 index 00000000000..297a46b861c --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties2.kt @@ -0,0 +1,40 @@ +// !API_VERSION: 1.3 +// !JVM_DEFAULT_MODE: compatibility +// 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 { + + val foo: T + + @JvmDefault + val bar: T + get() = foo +} + +interface KInterface2 : KInterface { + @JvmDefault + override val foo: String + get() = "OK" +} + + +fun box(): String { + return Foo().test() +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties3.kt b/compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties3.kt new file mode 100644 index 00000000000..daf9a5826b8 --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties3.kt @@ -0,0 +1,42 @@ +// !API_VERSION: 1.3 +// !JVM_DEFAULT_MODE: compatibility +// 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 { + + val foo: T + + @JvmDefault + val bar: T + get() = foo +} + +interface KInterface2 : KInterface { + @JvmDefault + override val foo: String + get() = "OK" +} + +interface KInterface3 : KInterface2 { + +} + + +fun box(): String { + return Foo().test() +} \ No newline at end of file diff --git a/compiler/testData/codegen/java8/bytecodeText/jvmDefault/compatibility/simpleProperty.kt b/compiler/testData/codegen/java8/bytecodeText/jvmDefault/compatibility/simpleProperty.kt new file mode 100644 index 00000000000..dfbf5b90112 --- /dev/null +++ b/compiler/testData/codegen/java8/bytecodeText/jvmDefault/compatibility/simpleProperty.kt @@ -0,0 +1,26 @@ +// !API_VERSION: 1.3 +// !JVM_DEFAULT_MODE: compatibility +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +interface KInterface { + + @JvmDefault + var bar: String + get() = "OK" + set(field) {} +} + +interface KInterface2 : KInterface { + +} + +// 1 INVOKESTATIC KInterface2.access\$getBar\$jd +// 1 INVOKESTATIC KInterface2.access\$setBar\$jd +// 1 INVOKESTATIC KInterface.access\$getBar\$jd +// 1 INVOKESTATIC KInterface.access\$setBar\$jd + +// 1 INVOKESPECIAL KInterface2.getBar +// 1 INVOKESPECIAL KInterface2.setBar +// 1 INVOKESPECIAL KInterface.getBar +// 1 INVOKESPECIAL KInterface.setBar \ 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 2d9f93d8d7e..594e6dfc7b9 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java @@ -508,6 +508,21 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg runTest("compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridge3.kt"); } + @TestMetadata("bridgeWithProperties.kt") + public void testBridgeWithProperties() throws Exception { + runTest("compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties.kt"); + } + + @TestMetadata("bridgeWithProperties2.kt") + public void testBridgeWithProperties2() throws Exception { + runTest("compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties2.kt"); + } + + @TestMetadata("bridgeWithProperties3.kt") + public void testBridgeWithProperties3() throws Exception { + runTest("compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/bridgeWithProperties3.kt"); + } + @TestMetadata("defaultArgs.kt") public void testDefaultArgs() throws Exception { runTest("compiler/testData/codegen/java8/box/jvm8/defaults/compatibility/defaultArgs.kt"); diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BytecodeTextJava8TestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BytecodeTextJava8TestGenerated.java index 4482b5643ad..fe066da2247 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BytecodeTextJava8TestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BytecodeTextJava8TestGenerated.java @@ -90,6 +90,11 @@ public class BytecodeTextJava8TestGenerated extends AbstractBytecodeTextTest { public void testSimpleFunctionWithAbstractOverride() throws Exception { runTest("compiler/testData/codegen/java8/bytecodeText/jvmDefault/compatibility/simpleFunctionWithAbstractOverride.kt"); } + + @TestMetadata("simpleProperty.kt") + public void testSimpleProperty() throws Exception { + runTest("compiler/testData/codegen/java8/bytecodeText/jvmDefault/compatibility/simpleProperty.kt"); + } } } }