Postpone JvmDefault deprecation. Revert "Deprecate @JvmDefault"

This reverts commit c11f3868
This commit is contained in:
Mikhail Bogdanov
2020-05-04 09:53:26 +02:00
parent 911dfde0fe
commit 4f7599076c
19 changed files with 57 additions and 73 deletions
@@ -289,7 +289,6 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
Note that if interface delegation is used, all interface methods are delegated. Note that if interface delegation is used, all interface methods are delegated.
The only exception are methods annotated with the deprecated @JvmDefault annotation. The only exception are methods annotated with the deprecated @JvmDefault annotation.
-Xjvm-default=disable Do not generate JVM default methods and prohibit @JvmDefault annotation usage. -Xjvm-default=disable Do not generate JVM default methods and prohibit @JvmDefault annotation usage.
The following modes are DEPRECATED:
-Xjvm-default=enable Allow usages of @JvmDefault; only generate the default method -Xjvm-default=enable Allow usages of @JvmDefault; only generate the default method
for annotated method in the interface for annotated method in the interface
(annotating an existing method can break binary compatibility) (annotating an existing method can break binary compatibility)
@@ -363,12 +362,6 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
result[AnalysisFlags.ignoreDataFlowInAssert] = JVMAssertionsMode.fromString(assertionsMode) != JVMAssertionsMode.LEGACY result[AnalysisFlags.ignoreDataFlowInAssert] = JVMAssertionsMode.fromString(assertionsMode) != JVMAssertionsMode.LEGACY
JvmDefaultMode.fromStringOrNull(jvmDefault)?.let { JvmDefaultMode.fromStringOrNull(jvmDefault)?.let {
result[JvmAnalysisFlags.jvmDefaultMode] = it result[JvmAnalysisFlags.jvmDefaultMode] = it
if (it == JvmDefaultMode.ENABLE || it == JvmDefaultMode.ENABLE_WITH_DEFAULT_IMPLS) {
collector.report(
CompilerMessageSeverity.WARNING,
"'-Xjvm-default=$jvmDefault' mode is deprecated. Please considering to switch to new modes: 'all' and 'all-compatibility'"
)
}
} ?: collector.report( } ?: collector.report(
CompilerMessageSeverity.ERROR, CompilerMessageSeverity.ERROR,
"Unknown @JvmDefault mode: $jvmDefault, " + "Unknown @JvmDefault mode: $jvmDefault, " +
-1
View File
@@ -57,7 +57,6 @@ where advanced options include:
Note that if interface delegation is used, all interface methods are delegated. Note that if interface delegation is used, all interface methods are delegated.
The only exception are methods annotated with the deprecated @JvmDefault annotation. The only exception are methods annotated with the deprecated @JvmDefault annotation.
-Xjvm-default=disable Do not generate JVM default methods and prohibit @JvmDefault annotation usage. -Xjvm-default=disable Do not generate JVM default methods and prohibit @JvmDefault annotation usage.
The following modes are DEPRECATED:
-Xjvm-default=enable Allow usages of @JvmDefault; only generate the default method -Xjvm-default=enable Allow usages of @JvmDefault; only generate the default method
for annotated method in the interface for annotated method in the interface
(annotating an existing method can break binary compatibility) (annotating an existing method can break binary compatibility)
@@ -2,7 +2,7 @@
// !JVM_DEFAULT_MODE: enable // !JVM_DEFAULT_MODE: enable
interface A<T> { interface A<T> {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
fun test(p: T) { fun test(p: T) {
} }
} }
@@ -13,7 +13,7 @@ public interface JavaInterface {
// FILE: 1.kt // FILE: 1.kt
interface KotlinInterface : JavaInterface { interface KotlinInterface : JavaInterface {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
override fun test() {} override fun test() {}
<!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {} <!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {}
@@ -22,7 +22,7 @@ interface KotlinInterface : JavaInterface {
} }
interface KotlinInterface2 : JavaInterface, KotlinInterface { interface KotlinInterface2 : JavaInterface, KotlinInterface {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
override fun test() {} override fun test() {}
override fun testForNonDefault() {} override fun testForNonDefault() {}
@@ -37,7 +37,7 @@ interface KotlinInterfaceForIndirect : JavaInterface {
interface KotlinInterfaceIndirectInheritance : KotlinInterfaceForIndirect { interface KotlinInterfaceIndirectInheritance : KotlinInterfaceForIndirect {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
override fun test() {} override fun test() {}
<!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {} <!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {}
@@ -63,7 +63,7 @@ interface KotlinInterfaceX {
} }
interface KotlinInterfaceManySuper: JavaInterface, KotlinInterfaceX { interface KotlinInterfaceManySuper: JavaInterface, KotlinInterfaceX {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
override fun test() {} override fun test() {}
<!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {} <!NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT!>override fun testForNonDefault()<!> {}
@@ -1,7 +1,7 @@
// !JVM_TARGET: 1.8 // !JVM_TARGET: 1.8
interface A { interface A {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
fun test()<!> { fun test()<!> {
} }
} }
@@ -28,7 +28,7 @@ class Bar2 : Foo(), A
class Bar3 : Foo(), B class Bar3 : Foo(), B
open class BarWithJvmDefault : B { open class BarWithJvmDefault : B {
<!JVM_DEFAULT_NOT_IN_INTERFACE!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_NOT_IN_INTERFACE!>@JvmDefault<!>
override fun test() { override fun test() {
} }
} }
@@ -2,12 +2,12 @@
// !JVM_TARGET: 1.8 // !JVM_TARGET: 1.8
public interface KInterface { public interface KInterface {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
fun test(): String { fun test(): String {
return "OK"; return "OK";
} }
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
val property: String val property: String
get() = "OK" get() = "OK"
@@ -23,7 +23,7 @@ public interface KInterface {
// FILE: 1.kt // FILE: 1.kt
interface KotlinInterface : KInterface { interface KotlinInterface : KInterface {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
fun fooo() { fun fooo() {
super.test() super.test()
super.property super.property
@@ -42,7 +42,7 @@ interface KotlinInterface : KInterface {
} }
} }
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
val propertyy: String val propertyy: String
get() { get() {
super.test() super.test()
@@ -105,7 +105,7 @@ interface KotlinInterface : KInterface {
} }
interface KotlinInterfaceIndirectInheritance : KotlinInterface { interface KotlinInterfaceIndirectInheritance : KotlinInterface {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
fun foooo() { fun foooo() {
super.test() super.test()
super.property super.property
@@ -124,7 +124,7 @@ interface KotlinInterfaceIndirectInheritance : KotlinInterface {
} }
} }
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
val propertyyy: String val propertyyy: String
get() { get() {
super.test() super.test()
@@ -15,7 +15,7 @@ public interface JavaInterface {
// FILE: 1.kt // FILE: 1.kt
interface KotlinInterface : JavaInterface { interface KotlinInterface : JavaInterface {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
fun fooo() { fun fooo() {
super.test() super.test()
@@ -26,7 +26,7 @@ interface KotlinInterface : JavaInterface {
} }
} }
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
val propertyy: String val propertyy: String
get() { get() {
super.test() super.test()
@@ -39,14 +39,14 @@ interface KotlinInterface : JavaInterface {
return "" return ""
} }
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
override fun testOverride(): String { override fun testOverride(): String {
return "OK"; return "OK";
} }
} }
interface KotlinInterfaceIndirectInheritance : KotlinInterface { interface KotlinInterfaceIndirectInheritance : KotlinInterface {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
fun foooo() { fun foooo() {
super.test() super.test()
@@ -57,7 +57,7 @@ interface KotlinInterfaceIndirectInheritance : KotlinInterface {
} }
} }
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
val propertyyy: String val propertyyy: String
get() { get() {
super.test() super.test()
@@ -2,27 +2,27 @@
interface B { interface B {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
fun test()<!> {} fun test()<!> {}
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
abstract fun test2(s: String = "")<!> abstract fun test2(s: String = "")<!>
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
abstract fun test3()<!> abstract fun test3()<!>
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
abstract val prop: String<!> abstract val prop: String<!>
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
abstract val prop2: String<!> abstract val prop2: String<!>
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
val prop3: String<!> val prop3: String<!>
get() = "" get() = ""
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
var prop4: String<!> var prop4: String<!>
get() = "" get() = ""
set(<!UNUSED_PARAMETER!>value<!>) {} set(<!UNUSED_PARAMETER!>value<!>) {}
@@ -2,21 +2,21 @@
abstract class A { abstract class A {
<!JVM_DEFAULT_NOT_IN_INTERFACE!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_NOT_IN_INTERFACE!>@JvmDefault<!>
fun test() {} fun test() {}
<!JVM_DEFAULT_NOT_IN_INTERFACE!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_NOT_IN_INTERFACE!>@JvmDefault<!>
abstract fun test2(s: String = "") abstract fun test2(s: String = "")
<!JVM_DEFAULT_NOT_IN_INTERFACE!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_NOT_IN_INTERFACE!>@JvmDefault<!>
abstract fun test3() abstract fun test3()
} }
object B { object B {
<!JVM_DEFAULT_NOT_IN_INTERFACE!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_NOT_IN_INTERFACE!>@JvmDefault<!>
fun test() {} fun test() {}
<!JVM_DEFAULT_NOT_IN_INTERFACE!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_NOT_IN_INTERFACE!>@JvmDefault<!>
fun test2(<!UNUSED_PARAMETER!>s<!>: String = "") {} fun test2(<!UNUSED_PARAMETER!>s<!>: String = "") {}
} }
@@ -3,12 +3,12 @@
interface B { interface B {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
val prop1: String val prop1: String
<!WRONG_ANNOTATION_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> get() = "" <!WRONG_ANNOTATION_TARGET!>@JvmDefault<!> get() = ""
var prop2: String var prop2: String
<!WRONG_ANNOTATION_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> get() = "" <!WRONG_ANNOTATION_TARGET!>@JvmDefault<!> get() = ""
<!WRONG_ANNOTATION_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> set(<!UNUSED_PARAMETER!>value<!>) {} <!WRONG_ANNOTATION_TARGET!>@JvmDefault<!> set(<!UNUSED_PARAMETER!>value<!>) {}
} }
@@ -2,7 +2,7 @@
// !JVM_DEFAULT_MODE: enable // !JVM_DEFAULT_MODE: enable
interface A { interface A {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
fun test() {} fun test() {}
} }
@@ -2,7 +2,7 @@
// !JVM_DEFAULT_MODE: enable // !JVM_DEFAULT_MODE: enable
interface A { interface A {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
val test: String val test: String
get() = "OK" get() = "OK"
} }
@@ -1,7 +1,7 @@
// !JVM_TARGET: 1.8 // !JVM_TARGET: 1.8
// FILE: 1.kt // FILE: 1.kt
interface A { interface A {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
fun test()<!> { fun test()<!> {
} }
} }
@@ -12,7 +12,7 @@ interface <!JVM_DEFAULT_THROUGH_INHERITANCE!>B<!> : A {
} }
interface C : B { interface C : B {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
override fun test()<!> { override fun test()<!> {
super.<!USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL!>test<!>() super.<!USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL!>test<!>()
} }
@@ -1,6 +1,6 @@
// !JVM_TARGET: 1.8 // !JVM_TARGET: 1.8
interface A { interface A {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
fun test()<!> { fun test()<!> {
} }
} }
@@ -16,7 +16,7 @@ interface B{
interface C : A, B { interface C : A, B {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
override fun test()<!> { override fun test()<!> {
super<B>.test() super<B>.test()
super<A>.<!USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL!>test<!>() super<A>.<!USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL!>test<!>()
@@ -24,7 +24,7 @@ interface C : A, B {
} }
interface D : B, A { interface D : B, A {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
override fun test()<!> { override fun test()<!> {
super<B>.test() super<B>.test()
super<A>.<!USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL!>test<!>() super<A>.<!USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL!>test<!>()
@@ -1,6 +1,6 @@
// !JVM_TARGET: 1.8 // !JVM_TARGET: 1.8
interface A { interface A {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
fun test()<!> fun test()<!>
} }
@@ -1,6 +1,6 @@
// !JVM_TARGET: 1.8 // !JVM_TARGET: 1.8
interface A { interface A {
<!JVM_DEFAULT_IN_DECLARATION!>@<!DEPRECATION!>JvmDefault<!> <!JVM_DEFAULT_IN_DECLARATION!>@JvmDefault
fun test()<!> { fun test()<!> {
} }
@@ -2,27 +2,27 @@
interface B { interface B {
<!JVM_DEFAULT_IN_JVM6_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefault<!>
fun test() {} fun test() {}
<!JVM_DEFAULT_IN_JVM6_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefault<!>
abstract fun test2(s: String = "") abstract fun test2(s: String = "")
<!JVM_DEFAULT_IN_JVM6_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefault<!>
abstract fun test3() abstract fun test3()
<!JVM_DEFAULT_IN_JVM6_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefault<!>
abstract val prop: String abstract val prop: String
<!JVM_DEFAULT_IN_JVM6_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefault<!>
abstract val prop2: String abstract val prop2: String
<!JVM_DEFAULT_IN_JVM6_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefault<!>
val prop3: String val prop3: String
get() = "" get() = ""
<!JVM_DEFAULT_IN_JVM6_TARGET!>@<!DEPRECATION!>JvmDefault<!><!> <!JVM_DEFAULT_IN_JVM6_TARGET!>@JvmDefault<!>
var prop4: String var prop4: String
get() = "" get() = ""
set(<!UNUSED_PARAMETER!>value<!>) {} set(<!UNUSED_PARAMETER!>value<!>) {}
@@ -3,27 +3,27 @@
interface B { interface B {
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
fun test() {} fun test() {}
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
abstract fun test2(s: String = "") abstract fun test2(s: String = "")
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
abstract fun test3() abstract fun test3()
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
abstract val prop: String abstract val prop: String
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
abstract val prop2: String abstract val prop2: String
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
val prop3: String val prop3: String
get() = "" get() = ""
@<!DEPRECATION!>JvmDefault<!> @JvmDefault
var prop4: String var prop4: String
get() = "" get() = ""
set(<!UNUSED_PARAMETER!>value<!>) {} set(<!UNUSED_PARAMETER!>value<!>) {}
@@ -27,16 +27,8 @@ import kotlin.internal.RequireKotlinVersionKind
* Generation of default methods is only possible with JVM target bytecode version 1.8 (`-jvm-target 1.8`) or higher. * Generation of default methods is only possible with JVM target bytecode version 1.8 (`-jvm-target 1.8`) or higher.
* *
* @[JvmDefault] methods are excluded from interface delegation. * @[JvmDefault] methods are excluded from interface delegation.
*
* #
* This annotation is **deprecated** in favor of new compiler arguments `-Xjvm-default=all-compatibility` and `-Xjvm-default=all`.
* The new arguments allow all interface methods with bodies to be generated as JVM default methods on JVM target 1.8+.
* Please refer to the [official documentation](https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#default-methods-in-interfaces)
* for more information.
*
*/ */
@SinceKotlin("1.2") @SinceKotlin("1.2")
@RequireKotlin("1.2.40", versionKind = RequireKotlinVersionKind.COMPILER_VERSION) @RequireKotlin("1.2.40", versionKind = RequireKotlinVersionKind.COMPILER_VERSION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
@Deprecated("Switch to new -Xjvm-default options: `all` or `all-compatibility`")
annotation class JvmDefault annotation class JvmDefault