JVM IR: don't rename fake overrides for fields
In case derived class has a field with the same name as the base class, RenameFieldsLowering previously tried to rename one of the fields by adding the "...$1" suffix, which led to NoSuchFieldError.
This commit is contained in:
Generated
+5
@@ -14619,6 +14619,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/jvmField/checkNoAccessors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("clashWithJavaSuperClassField.kt")
|
||||
public void testClashWithJavaSuperClassField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/clashWithJavaSuperClassField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classFieldReference.kt")
|
||||
public void testClassFieldReference() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/classFieldReference.kt");
|
||||
|
||||
+3
-1
@@ -96,7 +96,9 @@ private class FieldNameCollector : IrElementVisitorVoid {
|
||||
}
|
||||
|
||||
override fun visitField(declaration: IrField) {
|
||||
nameToField.getOrPut(declaration.parent to declaration.name) { mutableListOf() }.add(declaration)
|
||||
if (!declaration.isFakeOverride) {
|
||||
nameToField.getOrPut(declaration.parent to declaration.name) { mutableListOf() }.add(declaration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// FILE: test.kt
|
||||
|
||||
abstract class A {
|
||||
@JvmField
|
||||
protected var flag: String = "Fail"
|
||||
}
|
||||
|
||||
fun box(): String = object : J() {
|
||||
val result = flag
|
||||
}.result
|
||||
|
||||
// FILE: J.java
|
||||
|
||||
public class J extends A {
|
||||
protected String flag = "OK";
|
||||
}
|
||||
+5
@@ -15764,6 +15764,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/jvmField/checkNoAccessors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("clashWithJavaSuperClassField.kt")
|
||||
public void testClashWithJavaSuperClassField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/clashWithJavaSuperClassField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classFieldReference.kt")
|
||||
public void testClassFieldReference() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/classFieldReference.kt");
|
||||
|
||||
+5
@@ -15764,6 +15764,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/jvmField/checkNoAccessors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("clashWithJavaSuperClassField.kt")
|
||||
public void testClashWithJavaSuperClassField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/clashWithJavaSuperClassField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classFieldReference.kt")
|
||||
public void testClassFieldReference() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/classFieldReference.kt");
|
||||
|
||||
+5
@@ -14619,6 +14619,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/jvmField/checkNoAccessors.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("clashWithJavaSuperClassField.kt")
|
||||
public void testClashWithJavaSuperClassField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/clashWithJavaSuperClassField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classFieldReference.kt")
|
||||
public void testClassFieldReference() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvmField/classFieldReference.kt");
|
||||
|
||||
Reference in New Issue
Block a user