From 95654bb9bcba358118ae8d1b8162cedf2069660c Mon Sep 17 00:00:00 2001 From: Mikhail Bogdanov Date: Fri, 27 Mar 2020 15:56:55 +0100 Subject: [PATCH] Deprecate @JvmDefault #KT-40392 Fixed (cherry picked from commit c11f38688e271fcfd7e6781941a4bd7a0acc4b9a) --- .../annotations/jvmDefault/generic.kt | 2 +- .../annotations/jvmDefault/javaOverride.kt | 8 +- .../jvmDefault/javaOverrideAll.fir.kt | 69 ++++++++ .../annotations/jvmDefault/javaOverrideAll.kt | 3 +- .../jvmDefault/jvmDefaultInInheritance.kt | 4 +- .../annotations/jvmDefault/jvmDefaults.kt | 12 +- .../jvmDefault/jvmDefaultsWithJava.fir.kt | 162 ++++++++++++++++++ .../jvmDefault/jvmDefaultsWithJava.kt | 11 +- .../jvmDefault/noJvmDefaultFlag.kt | 14 +- .../annotations/jvmDefault/notInterface.kt | 10 +- .../jvmDefault/propertyAccessor.kt | 8 +- .../annotations/jvmDefault/simpleOverride.kt | 2 +- .../jvmDefault/simplePropertyOverride.kt | 2 +- .../annotations/jvmDefault/superCall.kt | 4 +- .../jvmDefault/superCallAmbiguity.kt | 6 +- .../jvmDefault/superCallAmbiguity2.kt | 2 +- .../jvmDefault/superCallAmbiguity3.kt | 2 +- .../annotations/jvmDefault/target6.kt | 14 +- .../annotations/jvmDefault/target8.kt | 14 +- .../stdlib/jvm/src/kotlin/jvm/JvmDefault.kt | 1 + 20 files changed, 290 insertions(+), 60 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverrideAll.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.fir.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt index 97f2b30d9b5..df3ea58ec10 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/generic.kt @@ -2,7 +2,7 @@ // !JVM_DEFAULT_MODE: enable interface A { - @JvmDefault + @JvmDefault fun test(p: T) { } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverride.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverride.kt index b7204e24613..9a87a0a26a0 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverride.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverride.kt @@ -13,7 +13,7 @@ public interface JavaInterface { // FILE: 1.kt interface KotlinInterface : JavaInterface { - @JvmDefault + @JvmDefault override fun test() {} override fun testForNonDefault() {} @@ -22,7 +22,7 @@ interface KotlinInterface : JavaInterface { } interface KotlinInterface2 : JavaInterface, KotlinInterface { - @JvmDefault + @JvmDefault override fun test() {} override fun testForNonDefault() {} @@ -37,7 +37,7 @@ interface KotlinInterfaceForIndirect : JavaInterface { interface KotlinInterfaceIndirectInheritance : KotlinInterfaceForIndirect { - @JvmDefault + @JvmDefault override fun test() {} override fun testForNonDefault() {} @@ -63,7 +63,7 @@ interface KotlinInterfaceX { } interface KotlinInterfaceManySuper: JavaInterface, KotlinInterfaceX { - @JvmDefault + @JvmDefault override fun test() {} override fun testForNonDefault() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverrideAll.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverrideAll.fir.kt new file mode 100644 index 00000000000..24835cb430a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverrideAll.fir.kt @@ -0,0 +1,69 @@ +// !JVM_DEFAULT_MODE: all +// !JVM_TARGET: 1.8 + +// FILE: JavaInterface.java +public interface JavaInterface { + default void test() {} + + default void testForNonDefault() {} + + void testAbstract(); +} + +// FILE: 1.kt + +interface KotlinInterface : JavaInterface { + @JvmDefault + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} + +interface KotlinInterface2 : JavaInterface, KotlinInterface { + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} + + +interface KotlinInterfaceForIndirect : JavaInterface { + +} + +interface KotlinInterfaceIndirectInheritance : KotlinInterfaceForIndirect { + + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} + +open class KotlinClass : JavaInterface { + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} + +interface KotlinInterfaceX { + + fun test() {} + + fun testForNonDefault() {} + + fun testAbstract() {} +} + +interface KotlinInterfaceManySuper: JavaInterface, KotlinInterfaceX { + override fun test() {} + + override fun testForNonDefault() {} + + override fun testAbstract() {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverrideAll.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverrideAll.kt index 66a25dff24c..99a4cb08f26 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverrideAll.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/javaOverrideAll.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !JVM_DEFAULT_MODE: all // !JVM_TARGET: 1.8 @@ -14,7 +13,7 @@ public interface JavaInterface { // FILE: 1.kt interface KotlinInterface : JavaInterface { - @JvmDefault + @JvmDefault override fun test() {} override fun testForNonDefault() {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultInInheritance.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultInInheritance.kt index e89e2deb868..3139cf76563 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultInInheritance.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultInInheritance.kt @@ -1,7 +1,7 @@ // !JVM_TARGET: 1.8 interface A { - @JvmDefault + @JvmDefault fun test() { } } @@ -28,7 +28,7 @@ class Bar2 : Foo(), A class Bar3 : Foo(), B open class BarWithJvmDefault : B { - @JvmDefault + @JvmDefault override fun test() { } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.kt index f7cb28811be..22820b64cd5 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaults.kt @@ -2,12 +2,12 @@ // !JVM_TARGET: 1.8 public interface KInterface { - @JvmDefault + @JvmDefault fun test(): String { return "OK"; } - @JvmDefault + @JvmDefault val property: String get() = "OK" @@ -23,7 +23,7 @@ public interface KInterface { // FILE: 1.kt interface KotlinInterface : KInterface { - @JvmDefault + @JvmDefault fun fooo() { super.test() super.property @@ -42,7 +42,7 @@ interface KotlinInterface : KInterface { } } - @JvmDefault + @JvmDefault val propertyy: String get() { super.test() @@ -105,7 +105,7 @@ interface KotlinInterface : KInterface { } interface KotlinInterfaceIndirectInheritance : KotlinInterface { - @JvmDefault + @JvmDefault fun foooo() { super.test() super.property @@ -124,7 +124,7 @@ interface KotlinInterfaceIndirectInheritance : KotlinInterface { } } - @JvmDefault + @JvmDefault val propertyyy: String get() { super.test() diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.fir.kt new file mode 100644 index 00000000000..b15d257c398 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.fir.kt @@ -0,0 +1,162 @@ +// !JVM_DEFAULT_MODE: enable +// !JVM_TARGET: 1.8 +// FILE: JavaInterface.java + +public interface JavaInterface { + default String test() { + return "OK"; + } + + default String testOverride() { + return "OK"; + } +} + +// FILE: 1.kt + +interface KotlinInterface : JavaInterface { + @JvmDefault + fun fooo() { + super.test() + + object { + fun run () { + super@KotlinInterface.test() + } + } + } + + @JvmDefault + val propertyy: String + get() { + super.test() + + object { + fun run () { + super@KotlinInterface.test() + } + } + return "" + } + + @JvmDefault + override fun testOverride(): String { + return "OK"; + } +} + +interface KotlinInterfaceIndirectInheritance : KotlinInterface { + @JvmDefault + fun foooo() { + super.test() + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + } + } + } + + @JvmDefault + val propertyyy: String + get() { + super.test() + + object { + fun run () { + super@KotlinInterfaceIndirectInheritance.test() + } + } + return "" + } +} + +open class KotlinClass : JavaInterface { + fun foo() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClass.test() + } + } + } + + val property: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClass.test() + } + } + return "" + } +} + +class KotlinClassIndirectInheritance : KotlinClass() { + fun foo2() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + } + } + } + + val property2: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance.test() + } + } + return "" + } +} + +class KotlinClassIndirectInheritance2 : KotlinInterfaceIndirectInheritance { + fun foo() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + } + } + } + + val property: String + get() { + super.test() + super.testOverride() + + object { + fun run () { + super@KotlinClassIndirectInheritance2.test() + } + } + return "" + } +} + +fun test() { + KotlinClass().foo() + KotlinClass().property + KotlinClassIndirectInheritance2().foo() + KotlinClassIndirectInheritance2().property + + KotlinClass().test() + KotlinClass().property + KotlinClass().testOverride() + KotlinClassIndirectInheritance().testOverride() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.kt index 7d4719d6868..8517f8efd38 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/jvmDefaultsWithJava.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !JVM_DEFAULT_MODE: enable // !JVM_TARGET: 1.8 // FILE: JavaInterface.java @@ -16,7 +15,7 @@ public interface JavaInterface { // FILE: 1.kt interface KotlinInterface : JavaInterface { - @JvmDefault + @JvmDefault fun fooo() { super.test() @@ -27,7 +26,7 @@ interface KotlinInterface : JavaInterface { } } - @JvmDefault + @JvmDefault val propertyy: String get() { super.test() @@ -40,14 +39,14 @@ interface KotlinInterface : JavaInterface { return "" } - @JvmDefault + @JvmDefault override fun testOverride(): String { return "OK"; } } interface KotlinInterfaceIndirectInheritance : KotlinInterface { - @JvmDefault + @JvmDefault fun foooo() { super.test() @@ -58,7 +57,7 @@ interface KotlinInterfaceIndirectInheritance : KotlinInterface { } } - @JvmDefault + @JvmDefault val propertyyy: String get() { super.test() diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/noJvmDefaultFlag.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/noJvmDefaultFlag.kt index 46fb4e1005e..70470e51d59 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/noJvmDefaultFlag.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/noJvmDefaultFlag.kt @@ -2,27 +2,27 @@ interface B { - @JvmDefault + @JvmDefault fun test() {} - @JvmDefault + @JvmDefault abstract fun test2(s: String = "") - @JvmDefault + @JvmDefault abstract fun test3() - @JvmDefault + @JvmDefault abstract val prop: String - @JvmDefault + @JvmDefault abstract val prop2: String - @JvmDefault + @JvmDefault val prop3: String get() = "" - @JvmDefault + @JvmDefault var prop4: String get() = "" set(value) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt index 7378e4a6338..800433dea87 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/notInterface.kt @@ -2,21 +2,21 @@ abstract class A { - @JvmDefault + @JvmDefault fun test() {} - @JvmDefault + @JvmDefault abstract fun test2(s: String = "") - @JvmDefault + @JvmDefault abstract fun test3() } object B { - @JvmDefault + @JvmDefault fun test() {} - @JvmDefault + @JvmDefault fun test2(s: String = "") {} } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt index ae9bf7ef203..247dd15cce9 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/propertyAccessor.kt @@ -3,12 +3,12 @@ interface B { - @JvmDefault + @JvmDefault val prop1: String - @JvmDefault get() = "" + @JvmDefault get() = "" var prop2: String - @JvmDefault get() = "" - @JvmDefault set(value) {} + @JvmDefault get() = "" + @JvmDefault set(value) {} } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt index e6f26e0eec0..9ac34d7ac9b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simpleOverride.kt @@ -2,7 +2,7 @@ // !JVM_DEFAULT_MODE: enable interface A { - @JvmDefault + @JvmDefault fun test() {} } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt index 202e083d645..5232315c24e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/simplePropertyOverride.kt @@ -2,7 +2,7 @@ // !JVM_DEFAULT_MODE: enable interface A { - @JvmDefault + @JvmDefault val test: String get() = "OK" } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCall.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCall.kt index 25304cc7a88..ce671f11388 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCall.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCall.kt @@ -1,7 +1,7 @@ // !JVM_TARGET: 1.8 // FILE: 1.kt interface A { - @JvmDefault + @JvmDefault fun test() { } } @@ -12,7 +12,7 @@ interface B : A { } interface C : B { - @JvmDefault + @JvmDefault override fun test() { super.test() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity.kt index a4c01edb548..5d0e9f1393f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity.kt @@ -1,6 +1,6 @@ // !JVM_TARGET: 1.8 interface A { - @JvmDefault + @JvmDefault fun test() { } } @@ -16,7 +16,7 @@ interface B{ interface C : A, B { - @JvmDefault + @JvmDefault override fun test() { super.test() super.test() @@ -24,7 +24,7 @@ interface C : A, B { } interface D : B, A { - @JvmDefault + @JvmDefault override fun test() { super.test() super.test() diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity2.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity2.kt index 88da42e2aed..4a5bfe788af 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity2.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity2.kt @@ -1,6 +1,6 @@ // !JVM_TARGET: 1.8 interface A { - @JvmDefault + @JvmDefault fun test() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity3.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity3.kt index 774d347ef4b..691f8288efc 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity3.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/superCallAmbiguity3.kt @@ -1,6 +1,6 @@ // !JVM_TARGET: 1.8 interface A { - @JvmDefault + @JvmDefault fun test() { } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt index 77391b331c3..e73f23b6fd5 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target6.kt @@ -2,27 +2,27 @@ interface B { - @JvmDefault + @JvmDefault fun test() {} - @JvmDefault + @JvmDefault abstract fun test2(s: String = "") - @JvmDefault + @JvmDefault abstract fun test3() - @JvmDefault + @JvmDefault abstract val prop: String - @JvmDefault + @JvmDefault abstract val prop2: String - @JvmDefault + @JvmDefault val prop3: String get() = "" - @JvmDefault + @JvmDefault var prop4: String get() = "" set(value) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt index cb0b02d8244..1421e03ba21 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmDefault/target8.kt @@ -3,27 +3,27 @@ interface B { - @JvmDefault + @JvmDefault fun test() {} - @JvmDefault + @JvmDefault abstract fun test2(s: String = "") - @JvmDefault + @JvmDefault abstract fun test3() - @JvmDefault + @JvmDefault abstract val prop: String - @JvmDefault + @JvmDefault abstract val prop2: String - @JvmDefault + @JvmDefault val prop3: String get() = "" - @JvmDefault + @JvmDefault var prop4: String get() = "" set(value) {} diff --git a/libraries/stdlib/jvm/src/kotlin/jvm/JvmDefault.kt b/libraries/stdlib/jvm/src/kotlin/jvm/JvmDefault.kt index 55d02d5f56b..aaf5d2772f5 100644 --- a/libraries/stdlib/jvm/src/kotlin/jvm/JvmDefault.kt +++ b/libraries/stdlib/jvm/src/kotlin/jvm/JvmDefault.kt @@ -31,6 +31,7 @@ import kotlin.internal.RequireKotlinVersionKind @SinceKotlin("1.2") @RequireKotlin("1.2.40", versionKind = RequireKotlinVersionKind.COMPILER_VERSION) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) +@Deprecated("Switch to new -Xjvm-default modes: `all` or `all-compatibility`") annotation class JvmDefault /**