[FIR] Fix references to generic synthetic properties
When synthetic properties are built from a substitution override, set originalForSubstitutionOverride, too. ^KT-56251 Fixed
This commit is contained in:
committed by
Space Team
parent
37760d1f2a
commit
b80970b09f
+6
@@ -3279,6 +3279,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/callableReference/publicMutableField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToGenericSyntheticProperty.kt")
|
||||
public void testReferenceToGenericSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/referenceToGenericSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("staticMethod.kt")
|
||||
public void testStaticMethod() throws Exception {
|
||||
|
||||
+6
@@ -352,6 +352,12 @@ public class FirLightTreeBlackBoxModernJdkCodegenTestGenerated extends AbstractF
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/bytecodeShapeForJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceToGenericRecord.kt")
|
||||
public void testCallableReferenceToGenericRecord() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/callableReferenceToGenericRecord.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("collectionSizeOverrides.kt")
|
||||
public void testCollectionSizeOverrides() throws Exception {
|
||||
|
||||
+6
@@ -3279,6 +3279,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/callableReference/publicMutableField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToGenericSyntheticProperty.kt")
|
||||
public void testReferenceToGenericSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/referenceToGenericSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("staticMethod.kt")
|
||||
public void testStaticMethod() throws Exception {
|
||||
|
||||
+6
@@ -352,6 +352,12 @@ public class FirPsiBlackBoxModernJdkCodegenTestGenerated extends AbstractFirPsiB
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/bytecodeShapeForJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceToGenericRecord.kt")
|
||||
public void testCallableReferenceToGenericRecord() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/callableReferenceToGenericRecord.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("collectionSizeOverrides.kt")
|
||||
public void testCollectionSizeOverrides() throws Exception {
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.buildSyntheticProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isStatic
|
||||
import org.jetbrains.kotlin.fir.scopes.*
|
||||
@@ -124,20 +125,13 @@ class FirSyntheticPropertiesScope private constructor(
|
||||
})
|
||||
}
|
||||
|
||||
val classLookupTag = getterSymbol.originalOrSelf().dispatchReceiverClassLookupTagOrNull()
|
||||
val packageName = classLookupTag?.classId?.packageFqName ?: getterSymbol.callableId.packageName
|
||||
val className = classLookupTag?.classId?.relativeClassName
|
||||
|
||||
val property = buildSyntheticProperty {
|
||||
moduleData = session.moduleData
|
||||
name = propertyName
|
||||
symbol = FirSimpleSyntheticPropertySymbol(
|
||||
getterId = getterSymbol.callableId,
|
||||
propertyId = CallableId(packageName, className, propertyName)
|
||||
val property = buildSyntheticProperty(propertyName, getter, matchingSetter)
|
||||
getter.originalForSubstitutionOverride?.let {
|
||||
property.originalForSubstitutionOverrideAttr = buildSyntheticProperty(
|
||||
propertyName,
|
||||
it,
|
||||
matchingSetter?.originalForSubstitutionOverride
|
||||
)
|
||||
delegateGetter = getter
|
||||
delegateSetter = matchingSetter
|
||||
deprecationsProvider = getDeprecationsProviderFromAccessors(session, getter, matchingSetter)
|
||||
}
|
||||
val syntheticSymbol = property.symbol
|
||||
(baseScope as? FirUnstableSmartcastTypeScope)?.apply {
|
||||
@@ -148,6 +142,24 @@ class FirSyntheticPropertiesScope private constructor(
|
||||
processor(syntheticSymbol)
|
||||
}
|
||||
|
||||
private fun buildSyntheticProperty(propertyName: Name, getter: FirSimpleFunction, setter: FirSimpleFunction?): FirSyntheticProperty {
|
||||
val classLookupTag = getter.symbol.originalOrSelf().dispatchReceiverClassLookupTagOrNull()
|
||||
val packageName = classLookupTag?.classId?.packageFqName ?: getter.symbol.callableId.packageName
|
||||
val className = classLookupTag?.classId?.relativeClassName
|
||||
|
||||
return buildSyntheticProperty {
|
||||
moduleData = session.moduleData
|
||||
name = propertyName
|
||||
symbol = FirSimpleSyntheticPropertySymbol(
|
||||
getterId = getter.symbol.callableId,
|
||||
propertyId = CallableId(packageName, className, propertyName)
|
||||
)
|
||||
delegateGetter = getter
|
||||
delegateSetter = setter
|
||||
deprecationsProvider = getDeprecationsProviderFromAccessors(session, getter, setter)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setterTypeIsConsistentWithGetterType(
|
||||
getterSymbol: FirNamedFunctionSymbol,
|
||||
parameterType: ConeKotlinType,
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isSynthetic
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
@@ -63,7 +64,7 @@ val FirCallableSymbol<*>.isSubstitutionOverride: Boolean get() = origin == FirDe
|
||||
val FirCallableSymbol<*>.isSubstitutionOrIntersectionOverride: Boolean get() = isSubstitutionOverride || isIntersectionOverride
|
||||
|
||||
inline val <reified D : FirCallableDeclaration> D.originalForSubstitutionOverride: D?
|
||||
get() = if (isSubstitutionOverride) originalForSubstitutionOverrideAttr else null
|
||||
get() = if (isSubstitutionOverride || isSynthetic) originalForSubstitutionOverrideAttr else null
|
||||
|
||||
inline val <reified S : FirCallableSymbol<*>> S.originalForSubstitutionOverride: S?
|
||||
get() = fir.originalForSubstitutionOverride?.symbol as S?
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_K1: JVM_IR
|
||||
// K1_STATUS: Broken because of KT-57103
|
||||
|
||||
// FILE: J.java
|
||||
|
||||
public class J<T> {
|
||||
private final T value;
|
||||
public J(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
val j = J("OK")
|
||||
if (j.value != "OK") return "FAIL"
|
||||
if (run(j::value) != "OK") return "FAIL"
|
||||
if (j.let(J<String>::value) != "OK") return "FAIL"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_K2: JVM_IR, JS_IR
|
||||
// IGNORE_BACKEND_K2: JS_IR
|
||||
// WITH_REFLECT
|
||||
// WITH_STDLIB
|
||||
// FILE: J.java
|
||||
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// ENABLE_JVM_PREVIEW
|
||||
|
||||
// FILE: R.java
|
||||
|
||||
public record R<T>(T value) {}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
val r = R("OK")
|
||||
if (r.value != "OK") return "FAIL"
|
||||
if (run(r::value) != "OK") return "FAIL"
|
||||
if (r.let(R<String>::value) != "OK") return "FAIL"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -3135,6 +3135,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/publicMutableField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToGenericSyntheticProperty.kt")
|
||||
public void testReferenceToGenericSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/referenceToGenericSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("staticMethod.kt")
|
||||
public void testStaticMethod() throws Exception {
|
||||
|
||||
+6
@@ -328,6 +328,12 @@ public class BlackBoxModernJdkCodegenTestGenerated extends AbstractBlackBoxCodeg
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/bytecodeShapeForJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceToGenericRecord.kt")
|
||||
public void testCallableReferenceToGenericRecord() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/callableReferenceToGenericRecord.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("collectionSizeOverrides.kt")
|
||||
public void testCollectionSizeOverrides() throws Exception {
|
||||
|
||||
+6
@@ -3279,6 +3279,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/publicMutableField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceToGenericSyntheticProperty.kt")
|
||||
public void testReferenceToGenericSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/referenceToGenericSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("staticMethod.kt")
|
||||
public void testStaticMethod() throws Exception {
|
||||
|
||||
+6
@@ -352,6 +352,12 @@ public class IrBlackBoxModernJdkCodegenTestGenerated extends AbstractIrBlackBoxC
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/bytecodeShapeForJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceToGenericRecord.kt")
|
||||
public void testCallableReferenceToGenericRecord() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxModernJdk/testsWithJava17/records/callableReferenceToGenericRecord.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("collectionSizeOverrides.kt")
|
||||
public void testCollectionSizeOverrides() throws Exception {
|
||||
|
||||
+5
@@ -2743,6 +2743,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/publicMutableField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceToGenericSyntheticProperty.kt")
|
||||
public void testReferenceToGenericSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/referenceToGenericSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("staticMethod.kt")
|
||||
public void testStaticMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/staticMethod.kt");
|
||||
|
||||
Reference in New Issue
Block a user