-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JvmDefault. Allow non default inheritance with special flag
#KT-47000 (cherry picked from commit afc149d)
- Loading branch information
Mikhael Bogdanov
authored and
Space
committed
Nov 9, 2021
1 parent
206d7d9
commit ddd02fe
Showing
24 changed files
with
464 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
compiler/testData/codegen/box/jvm8/defaults/nonDefaultInheritance/simple.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// TARGET_BACKEND: JVM | ||
// IGNORE_BACKEND_FIR: JVM_IR | ||
// FULL_JDK | ||
// JVM_TARGET: 1.8 | ||
// WITH_RUNTIME | ||
// MODULE: lib | ||
// !JVM_DEFAULT_MODE: all | ||
// FILE: Foo.kt | ||
|
||
interface Foo { | ||
fun toOverride(): String = "fail" | ||
|
||
fun nonOverride(): String = "K" | ||
} | ||
|
||
// MODULE: main(lib) | ||
// !JVM_DEFAULT_MODE: disable | ||
// !JVM_DEFAULT_ALLOW_NON_DEFAULT_INHERITANCE | ||
// FILE: main.kt | ||
|
||
interface Derived : Foo { | ||
override fun toOverride(): String { | ||
return "O" | ||
} | ||
} | ||
|
||
class DerivedClass : Derived | ||
|
||
|
||
fun box(): String { | ||
checkMethodExists(DerivedClass::class.java, "toOverride") | ||
checkNoMethod(DerivedClass::class.java, "nonOverride") | ||
|
||
val value = DerivedClass() | ||
return value.toOverride() + value.nonOverride() | ||
} | ||
|
||
fun checkNoMethod(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) { | ||
try { | ||
clazz.getDeclaredMethod(name, *parameterTypes) | ||
} | ||
catch (e: NoSuchMethodException) { | ||
return | ||
} | ||
throw AssertionError("fail: method $name was found in " + clazz) | ||
} | ||
|
||
fun checkMethodExists(clazz: Class<*>, name: String, vararg parameterTypes: Class<*>) { | ||
try { | ||
clazz.getDeclaredMethod(name, *parameterTypes) | ||
return | ||
} | ||
catch (e: NoSuchMethodException) { | ||
throw AssertionError("fail: method $name was not found in " + clazz, e) | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
compiler/testData/codegen/box/jvm8/defaults/nonDefaultInheritance/simple2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// TARGET_BACKEND: JVM | ||
// IGNORE_BACKEND_FIR: JVM_IR | ||
// FULL_JDK | ||
// JVM_TARGET: 1.8 | ||
// WITH_RUNTIME | ||
// MODULE: lib | ||
// !JVM_DEFAULT_MODE: all | ||
// FILE: Foo.kt | ||
|
||
interface Foo { | ||
fun toOverride(): List<String> = null!! | ||
|
||
fun nonOverride(): List<String> = Thread.currentThread().getStackTrace().map { it.className + "." + it.methodName } | ||
} | ||
|
||
// MODULE: main(lib) | ||
// !JVM_DEFAULT_MODE: disable | ||
// !JVM_DEFAULT_ALLOW_NON_DEFAULT_INHERITANCE | ||
// FILE: main.kt | ||
|
||
interface Derived : Foo { | ||
override fun toOverride() = Thread.currentThread().getStackTrace().map { it.className + "." + it.methodName } | ||
} | ||
|
||
class DerivedClass : Derived | ||
|
||
|
||
fun box(): String { | ||
val override = DerivedClass().toOverride() | ||
if (override[1] != "Derived\$DefaultImpls.toOverride") return "fail 1: ${override[1]}" | ||
if (override[2] != "DerivedClass.toOverride") return "fail 2: ${override[2]}" | ||
if (override[3] != "MainKt.box") return "fail 3: ${override[3]}" | ||
|
||
val nonOverride = DerivedClass().nonOverride() | ||
if (nonOverride[1] != "Foo.nonOverride") return "fail 3: ${nonOverride[1]}" | ||
if (nonOverride[2] != "MainKt.box") return "fail 4: ${nonOverride[2]}" | ||
|
||
return "OK" | ||
} |
32 changes: 32 additions & 0 deletions
32
compiler/testData/codegen/box/jvm8/defaults/nonDefaultInheritance/specialization.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// CHECK_BYTECODE_LISTING | ||
// TARGET_BACKEND: JVM | ||
// IGNORE_BACKEND_FIR: JVM_IR | ||
// JVM_TARGET: 1.8 | ||
// WITH_RUNTIME | ||
// MODULE: lib | ||
// !JVM_DEFAULT_MODE: all | ||
// FILE: Foo.kt | ||
|
||
interface Foo<T> { | ||
fun foo(p: T) = p | ||
} | ||
|
||
interface Foo2<T> { | ||
fun foo(p: T): T = null!! | ||
} | ||
|
||
// MODULE: main(lib) | ||
// !JVM_DEFAULT_MODE: disable | ||
// !JVM_DEFAULT_ALLOW_NON_DEFAULT_INHERITANCE | ||
// FILE: main.kt | ||
class DerivedClass : Foo<String> | ||
|
||
interface DerivedInterface<T> : Foo2<T> { | ||
override fun foo(p: T) = p | ||
} | ||
|
||
class DerivedClassWithSpecialization : DerivedInterface<String> | ||
|
||
fun box(): String { | ||
return DerivedClass().foo("O") + DerivedClassWithSpecialization().foo("K") | ||
} |
46 changes: 46 additions & 0 deletions
46
compiler/testData/codegen/box/jvm8/defaults/nonDefaultInheritance/specialization.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Module: lib | ||
@kotlin.Metadata | ||
public interface Foo { | ||
// source: 'Foo.kt' | ||
public method foo(p0: java.lang.Object): java.lang.Object | ||
} | ||
|
||
@kotlin.Metadata | ||
public interface Foo2 { | ||
// source: 'Foo.kt' | ||
public method foo(p0: java.lang.Object): java.lang.Object | ||
} | ||
Module: main | ||
@kotlin.Metadata | ||
public final class DerivedClass { | ||
// source: 'main.kt' | ||
public method <init>(): void | ||
} | ||
|
||
@kotlin.Metadata | ||
public final class DerivedClassWithSpecialization { | ||
// source: 'main.kt' | ||
public method <init>(): void | ||
public @org.jetbrains.annotations.NotNull method foo(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String | ||
public synthetic bridge method foo(p0: java.lang.Object): java.lang.Object | ||
} | ||
|
||
@kotlin.Metadata | ||
public final class DerivedInterface$DefaultImpls { | ||
// source: 'main.kt' | ||
public static method foo(@org.jetbrains.annotations.NotNull p0: DerivedInterface, p1: java.lang.Object): java.lang.Object | ||
public final inner class DerivedInterface$DefaultImpls | ||
} | ||
|
||
@kotlin.Metadata | ||
public interface DerivedInterface { | ||
// source: 'main.kt' | ||
public abstract method foo(p0: java.lang.Object): java.lang.Object | ||
public final inner class DerivedInterface$DefaultImpls | ||
} | ||
|
||
@kotlin.Metadata | ||
public final class MainKt { | ||
// source: 'main.kt' | ||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String | ||
} |
26 changes: 26 additions & 0 deletions
26
compiler/testData/codegen/box/jvm8/defaults/nonDefaultInheritance/superCall.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// CHECK_BYTECODE_LISTING | ||
// TARGET_BACKEND: JVM | ||
// IGNORE_BACKEND_FIR: JVM_IR | ||
// JVM_TARGET: 1.8 | ||
// WITH_RUNTIME | ||
// MODULE: lib | ||
// !JVM_DEFAULT_MODE: all | ||
// FILE: Foo.kt | ||
|
||
interface Foo<T> { | ||
fun foo(p: T) = p | ||
} | ||
|
||
// MODULE: main(lib) | ||
// !JVM_DEFAULT_MODE: disable | ||
// !JVM_DEFAULT_ALLOW_NON_DEFAULT_INHERITANCE | ||
// FILE: main.kt | ||
interface DerivedInterface<T> : Foo<T> | ||
|
||
class DerivedClass : DerivedInterface<String> { | ||
override fun foo(p: String) = super.foo(p) | ||
} | ||
|
||
fun box(): String { | ||
return DerivedClass().foo("OK") | ||
} |
25 changes: 25 additions & 0 deletions
25
compiler/testData/codegen/box/jvm8/defaults/nonDefaultInheritance/superCall.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Module: lib | ||
@kotlin.Metadata | ||
public interface Foo { | ||
// source: 'Foo.kt' | ||
public method foo(p0: java.lang.Object): java.lang.Object | ||
} | ||
Module: main | ||
@kotlin.Metadata | ||
public final class DerivedClass { | ||
// source: 'main.kt' | ||
public method <init>(): void | ||
public @org.jetbrains.annotations.NotNull method foo(@org.jetbrains.annotations.NotNull p0: java.lang.String): java.lang.String | ||
public synthetic bridge method foo(p0: java.lang.Object): java.lang.Object | ||
} | ||
|
||
@kotlin.Metadata | ||
public interface DerivedInterface { | ||
// source: 'main.kt' | ||
} | ||
|
||
@kotlin.Metadata | ||
public final class MainKt { | ||
// source: 'main.kt' | ||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String | ||
} |
5 changes: 5 additions & 0 deletions
5
.../compileKotlinAgainstCustomBinaries/jvmDefaultNonDefaultInheritanceSuperCall/library/a.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package base | ||
|
||
interface UExpression { | ||
fun evaluate(): Any? = "fail" | ||
} |
7 changes: 7 additions & 0 deletions
7
...ta/compileKotlinAgainstCustomBinaries/jvmDefaultNonDefaultInheritanceSuperCall/output.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
compiler/testData/compileKotlinAgainstCustomBinaries/jvmDefaultNonDefaultInheritanceSuperCall/source.kt:5:22: error: interfaces can call JVM-default members via super only within JVM-default members. Please use '-Xjvm-default=all/all-compatibility' modes for such calls | ||
return super.evaluate() | ||
^ | ||
compiler/testData/compileKotlinAgainstCustomBinaries/jvmDefaultNonDefaultInheritanceSuperCall/source.kt:5:22: error: super calls of '@JvmDefault' members are only allowed with -Xjvm-default option | ||
return super.evaluate() | ||
^ | ||
COMPILATION_ERROR |
7 changes: 7 additions & 0 deletions
7
...ata/compileKotlinAgainstCustomBinaries/jvmDefaultNonDefaultInheritanceSuperCall/source.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import base.* | ||
|
||
interface KotlinEvaluatableUElement : UExpression { | ||
override fun evaluate(): Any? { | ||
return super.evaluate() | ||
} | ||
} |
Oops, something went wrong.