FIR: Fix wrong ACCIDENTAL_OVERRIDE on fake override property with JvmName

This commit is contained in:
Denis.Zharkov
2021-11-10 18:15:22 +03:00
committed by teamcityserver
parent 6f55d23bab
commit a7859e0332
7 changed files with 69 additions and 10 deletions
@@ -504,7 +504,7 @@ class Fir2IrDeclarationStorage(
containerSource = simpleFunction?.containerSource, containerSource = simpleFunction?.containerSource,
).apply { ).apply {
metadata = FirMetadataSource.Function(function) metadata = FirMetadataSource.Function(function)
convertAnnotationsFromLibrary(function) convertAnnotationsForNonDeclaredMembers(function, origin)
enterScope(this) enterScope(this)
bindAndDeclareParameters( bindAndDeclareParameters(
function, irParent, function, irParent,
@@ -626,6 +626,7 @@ class Fir2IrDeclarationStorage(
endOffset: Int, endOffset: Int,
isLocal: Boolean = false, isLocal: Boolean = false,
containingClass: ConeClassLikeLookupTag? = null, containingClass: ConeClassLikeLookupTag? = null,
propertyAccessorForAnnotations: FirPropertyAccessor? = propertyAccessor,
): IrSimpleFunction = convertCatching(propertyAccessor ?: property) { ): IrSimpleFunction = convertCatching(propertyAccessor ?: property) {
val prefix = if (isSetter) "set" else "get" val prefix = if (isSetter) "set" else "get"
val signature = if (isLocal) null else signatureComposer.composeAccessorSignature(property, isSetter, containingClass) val signature = if (isLocal) null else signatureComposer.composeAccessorSignature(property, isSetter, containingClass)
@@ -654,7 +655,11 @@ class Fir2IrDeclarationStorage(
if (propertyAccessor != null) { if (propertyAccessor != null) {
metadata = FirMetadataSource.Function(propertyAccessor) metadata = FirMetadataSource.Function(propertyAccessor)
// Note that deserialized annotations are stored in the accessor, not the property. // Note that deserialized annotations are stored in the accessor, not the property.
convertAnnotationsFromLibrary(propertyAccessor) convertAnnotationsForNonDeclaredMembers(propertyAccessor, origin)
}
if (propertyAccessorForAnnotations != null) {
convertAnnotationsForNonDeclaredMembers(propertyAccessorForAnnotations, origin)
} }
with(classifierStorage) { with(classifierStorage) {
setTypeParameters( setTypeParameters(
@@ -710,7 +715,7 @@ class Fir2IrDeclarationStorage(
it.correspondingPropertySymbol = this@createBackingField.symbol it.correspondingPropertySymbol = this@createBackingField.symbol
}.apply { }.apply {
metadata = FirMetadataSource.Property(property) metadata = FirMetadataSource.Property(property)
convertAnnotationsFromLibrary(property) convertAnnotationsForNonDeclaredMembers(property, origin)
} }
} }
} }
@@ -812,7 +817,7 @@ class Fir2IrDeclarationStorage(
containerSource = property.containerSource, containerSource = property.containerSource,
).apply { ).apply {
metadata = FirMetadataSource.Property(property) metadata = FirMetadataSource.Property(property)
convertAnnotationsFromLibrary(property) convertAnnotationsForNonDeclaredMembers(property, origin)
enterScope(this) enterScope(this)
if (irParent != null) { if (irParent != null) {
parent = irParent parent = irParent
@@ -860,7 +865,8 @@ class Fir2IrDeclarationStorage(
getter is FirDefaultPropertyGetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR getter is FirDefaultPropertyGetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
else -> origin else -> origin
}, },
startOffset, endOffset, isLocal, containingClass startOffset, endOffset, isLocal, containingClass,
property.unwrapFakeOverrides().getter,
) )
if (property.isVar) { if (property.isVar) {
this.setter = createIrPropertyAccessor( this.setter = createIrPropertyAccessor(
@@ -870,7 +876,8 @@ class Fir2IrDeclarationStorage(
setter is FirDefaultPropertySetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR setter is FirDefaultPropertySetter -> IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
else -> origin else -> origin
}, },
startOffset, endOffset, isLocal, containingClass startOffset, endOffset, isLocal, containingClass,
property.unwrapFakeOverrides().setter,
) )
} }
leaveScope(this) leaveScope(this)
@@ -1403,10 +1410,10 @@ class Fir2IrDeclarationStorage(
} }
} }
private fun IrMutableAnnotationContainer.convertAnnotationsFromLibrary(firAnnotationContainer: FirAnnotationContainer) { private fun IrMutableAnnotationContainer.convertAnnotationsForNonDeclaredMembers(
if ((firAnnotationContainer as? FirDeclaration)?.isFromLibrary == true || firAnnotationContainer: FirAnnotationContainer, origin: IrDeclarationOrigin,
(firAnnotationContainer is FirCallableDeclaration && firAnnotationContainer.isSubstitutionOrIntersectionOverride) ) {
) { if ((firAnnotationContainer as? FirDeclaration)?.isFromLibrary == true || origin == IrDeclarationOrigin.FAKE_OVERRIDE) {
annotationGenerator.generate(this, firAnnotationContainer) annotationGenerator.generate(this, firAnnotationContainer)
} }
} }
@@ -25804,6 +25804,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt"); runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt");
} }
@Test
@TestMetadata("fakeOverrideOfProperty.kt")
public void testFakeOverrideOfProperty() throws Exception {
runTest("compiler/testData/codegen/box/jvmName/fakeOverrideOfProperty.kt");
}
@Test @Test
@TestMetadata("functionName.kt") @TestMetadata("functionName.kt")
public void testFunctionName() throws Exception { public void testFunctionName() throws Exception {
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
abstract class Base {
protected abstract fun getChart(context: CharSequence): String
@get:JvmName("getChartHelper")
public val CharSequence.chart get() = getChart(this)
}
abstract class Derived1 : Base()
class Derived2 : Derived1() {
override fun getChart(context: CharSequence): String {
return context.toString()
}
}
fun box(): String {
return with(Derived2()) {
"OK".chart
}
}
@@ -25642,6 +25642,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt"); runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt");
} }
@Test
@TestMetadata("fakeOverrideOfProperty.kt")
public void testFakeOverrideOfProperty() throws Exception {
runTest("compiler/testData/codegen/box/jvmName/fakeOverrideOfProperty.kt");
}
@Test @Test
@TestMetadata("functionName.kt") @TestMetadata("functionName.kt")
public void testFunctionName() throws Exception { public void testFunctionName() throws Exception {
@@ -25804,6 +25804,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt"); runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt");
} }
@Test
@TestMetadata("fakeOverrideOfProperty.kt")
public void testFakeOverrideOfProperty() throws Exception {
runTest("compiler/testData/codegen/box/jvmName/fakeOverrideOfProperty.kt");
}
@Test @Test
@TestMetadata("functionName.kt") @TestMetadata("functionName.kt")
public void testFunctionName() throws Exception { public void testFunctionName() throws Exception {
@@ -21628,6 +21628,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt"); runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt");
} }
@TestMetadata("fakeOverrideOfProperty.kt")
public void testFakeOverrideOfProperty() throws Exception {
runTest("compiler/testData/codegen/box/jvmName/fakeOverrideOfProperty.kt");
}
@TestMetadata("functionName.kt") @TestMetadata("functionName.kt")
public void testFunctionName() throws Exception { public void testFunctionName() throws Exception {
runTest("compiler/testData/codegen/box/jvmName/functionName.kt"); runTest("compiler/testData/codegen/box/jvmName/functionName.kt");
@@ -26115,6 +26115,12 @@ public class NativeExtBlackBoxTestGenerated extends AbstractNativeBlackBoxTest {
runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt"); runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt");
} }
@Test
@TestMetadata("fakeOverrideOfProperty.kt")
public void testFakeOverrideOfProperty() throws Exception {
runTest("compiler/testData/codegen/box/jvmName/fakeOverrideOfProperty.kt");
}
@Test @Test
@TestMetadata("functionName.kt") @TestMetadata("functionName.kt")
public void testFunctionName() throws Exception { public void testFunctionName() throws Exception {