JVM_IR: handle diamond inheritance for Java fields
This commit is contained in:
Generated
+5
@@ -16014,6 +16014,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/jvmField/constructorProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("diamond.kt")
|
||||
public void testDiamond() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/diamond.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("fileOrder.kt")
|
||||
public void testFileOrder() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/fileOrder.kt");
|
||||
|
||||
@@ -79,12 +79,13 @@ val PropertyDescriptor.unwrappedSetMethod: FunctionDescriptor?
|
||||
|
||||
// Only works for descriptors of Java fields.
|
||||
internal fun PropertyDescriptor.resolveFakeOverride(): PropertyDescriptor {
|
||||
assert(getter == null)
|
||||
// Fields can only be inherited from objects, so there will be at most one overridden descriptor at each step.
|
||||
assert(getter == null) { "resolveFakeOverride should only be called for Java fields, got $this"}
|
||||
var current = this
|
||||
while (current.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||
current = current.overriddenDescriptors.singleOrNull()
|
||||
?: error("Descriptor of Java field $current should have exactly one overridden descriptor, have ${current.overriddenDescriptors}")
|
||||
current = current.overriddenDescriptors.singleOrNull {
|
||||
(it.containingDeclaration as ClassDescriptor).kind != ClassKind.INTERFACE
|
||||
} ?: current.overriddenDescriptors.firstOrNull()
|
||||
?: error("Fake override descriptor of Java field $current should has no overridden descriptors")
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// FILE: A.java
|
||||
public interface A { public String ok = "OK"; }
|
||||
// FILE: B.java
|
||||
public class B implements A {}
|
||||
// FILE: C.java
|
||||
public class C extends B implements A {}
|
||||
// FILE: test.kt
|
||||
class D: C() {
|
||||
fun okay() = ok
|
||||
}
|
||||
|
||||
fun box() = D().okay()
|
||||
+5
@@ -17239,6 +17239,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/jvmField/constructorProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("diamond.kt")
|
||||
public void testDiamond() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/diamond.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("fileOrder.kt")
|
||||
public void testFileOrder() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/fileOrder.kt");
|
||||
|
||||
+5
@@ -17239,6 +17239,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/jvmField/constructorProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("diamond.kt")
|
||||
public void testDiamond() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/diamond.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("fileOrder.kt")
|
||||
public void testFileOrder() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/fileOrder.kt");
|
||||
|
||||
+5
@@ -16014,6 +16014,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/jvmField/constructorProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("diamond.kt")
|
||||
public void testDiamond() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/diamond.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("fileOrder.kt")
|
||||
public void testFileOrder() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/fileOrder.kt");
|
||||
|
||||
Reference in New Issue
Block a user