JvmDefault: remove most tests on @JvmDefault

The tests are removed because JvmDefault is going to be deprecated with
error in KT-54746 and removed later in KT-57696.

Many of the removed tests already had existing counterparts with the new
modes `all` and `all-compatibility`. In this change, I've added such
tests where they were missing, and removed tests which were testing
behavior specific to the JvmDefault annotation, such as some
diagnostics.

 #KT-54746
This commit is contained in:
Alexander Udalov
2023-03-31 01:06:32 +02:00
committed by Space Team
parent ace2279631
commit 3120a35a88
210 changed files with 1267 additions and 7917 deletions
@@ -0,0 +1,22 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
interface Test {
fun foo(): String = "O"
val bar: String
get() = "K"
fun test(): String {
return (::foo).let { it() } + (::bar).let { it() }
}
}
class TestClass : Test {
}
fun box(): String {
return TestClass().test()
}
@@ -0,0 +1,28 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_STDLIB
interface IBase {
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()
}
@@ -4,29 +4,16 @@
// WITH_STDLIB
interface Test {
@JvmDefault
fun test(): String {
return "O"
}
fun delegatedTest(): String {
return "fail"
}
fun test(): String = "Fail"
}
class Delegate : Test {
override fun test(): String {
return "Fail"
}
override fun delegatedTest(): String {
return "K"
}
override fun test(): String = "OK"
}
class TestClass(val foo: Test) : Test by foo
fun box(): String {
val testClass = TestClass(Delegate())
return testClass.test() + testClass.delegatedTest()
return testClass.test()
}
@@ -4,26 +4,16 @@
// WITH_STDLIB
interface Test {
@JvmDefault
val test: String
get() = "O"
val testDelegated: String
get() = "fail"
val test: String get() = "Fail"
}
class Delegate : Test {
override val test: String
get() = "fail"
override val testDelegated: String
get() = "K"
override val test: String get() = "OK"
}
class TestClass(val foo: Test) : Test by foo
fun box(): String {
val testClass = TestClass(Delegate())
return testClass.test + testClass.testDelegated
return testClass.test
}
@@ -0,0 +1,19 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// FULL_JDK
// WITH_STDLIB
interface IFoo {
fun foo() {}
}
fun box(): String {
val iFoo = IFoo::class.java
val iFooDefaultImpls = Class.forName("${iFoo.name}\$DefaultImpls")
val fooMethod = iFooDefaultImpls.declaredMethods.find { it.name == "foo" }
?: throw AssertionError("No method 'foo' in class ${iFooDefaultImpls.name}")
fooMethod.getAnnotation(java.lang.Deprecated::class.java)
?: throw AssertionError("No java.lang.Deprecated annotation on method 'foo'")
return "OK"
}
@@ -0,0 +1,52 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: ANDROID
// JVM_TARGET: 1.8
// WITH_REFLECT
// FULL_JDK
interface Test {
fun test(): String {
return "Test"
}
}
open class TestClass : Test {
}
interface Test2 : Test {
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: method $name was found in " + clazz)
}
@@ -0,0 +1,22 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_STDLIB
// IGNORE_INLINER: IR
interface Test {
fun test(): String {
return inlineFun { "OK" }
}
private inline fun inlineFun(s: () -> String) = s()
}
class TestClass : Test {
}
fun box(): String {
val foo = TestClass()
return foo.test()
}
@@ -0,0 +1,22 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_STDLIB
// IGNORE_INLINER: IR
interface Test {
fun test(): String {
return inlineProp
}
private inline val inlineProp: String
get() = "OK"
}
class TestClass : Test {
}
fun box(): String =
TestClass().test()
@@ -0,0 +1,56 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: ANDROID
// JVM_TARGET: 1.8
// WITH_STDLIB
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 != "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"
}
@@ -0,0 +1,27 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_STDLIB
interface Z<T> {
val value: T
val z: T
get() = value
}
@JvmDefaultWithoutCompatibility
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,27 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_STDLIB
// FILE: JBase.java
public interface JBase extends Base {
default String test() {
return "OK";
}
}
// FILE: main.kt
interface Base {
fun test(): String = "Base"
}
interface LeftBase : Base
interface Right : JBase
interface Child : LeftBase, Right
fun box(): String {
return object : Child {}.test()
}
@@ -0,0 +1,23 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_STDLIB
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,28 @@
// !JVM_DEFAULT_MODE: all-compatibility
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_STDLIB
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
}