KT-8575 Add tests and disable reflection for Java synthetic property references
This commit is contained in:
committed by
teamcity
parent
5116bbc440
commit
f8fd23e373
@@ -157,13 +157,15 @@ private fun FirBasedSymbol<*>.toSymbolForCall(
|
||||
dispatchReceiver: FirExpression,
|
||||
preferGetter: Boolean,
|
||||
explicitReceiver: FirExpression? = null,
|
||||
isDelegate: Boolean = false
|
||||
isDelegate: Boolean = false,
|
||||
isReference: Boolean = false
|
||||
): IrSymbol? = when (this) {
|
||||
is FirCallableSymbol<*> -> unwrapCallRepresentative().toSymbolForCall(
|
||||
dispatchReceiver,
|
||||
preferGetter,
|
||||
explicitReceiver,
|
||||
isDelegate
|
||||
isDelegate,
|
||||
isReference
|
||||
)
|
||||
is FirClassifierSymbol<*> -> toSymbol()
|
||||
else -> error("Unknown symbol: $this")
|
||||
@@ -175,7 +177,8 @@ fun FirReference.toSymbolForCall(
|
||||
conversionScope: Fir2IrConversionScope,
|
||||
preferGetter: Boolean = true,
|
||||
explicitReceiver: FirExpression? = null, // Actual only for callable references
|
||||
isDelegate: Boolean = false
|
||||
isDelegate: Boolean = false,
|
||||
isReference: Boolean = false
|
||||
): IrSymbol? {
|
||||
return when (this) {
|
||||
is FirResolvedNamedReference ->
|
||||
@@ -183,14 +186,16 @@ fun FirReference.toSymbolForCall(
|
||||
dispatchReceiver,
|
||||
preferGetter,
|
||||
explicitReceiver,
|
||||
isDelegate
|
||||
isDelegate,
|
||||
isReference
|
||||
)
|
||||
is FirErrorNamedReference ->
|
||||
candidateSymbol?.toSymbolForCall(
|
||||
dispatchReceiver,
|
||||
preferGetter,
|
||||
explicitReceiver,
|
||||
isDelegate
|
||||
isDelegate,
|
||||
isReference
|
||||
)
|
||||
is FirThisReference -> {
|
||||
when (val boundSymbol = boundSymbol) {
|
||||
@@ -212,7 +217,8 @@ private fun FirCallableSymbol<*>.toSymbolForCall(
|
||||
dispatchReceiver: FirExpression,
|
||||
preferGetter: Boolean,
|
||||
explicitReceiver: FirExpression? = null,
|
||||
isDelegate: Boolean = false
|
||||
isDelegate: Boolean = false,
|
||||
isReference: Boolean = false
|
||||
): IrSymbol? {
|
||||
val dispatchReceiverLookupTag = when {
|
||||
dispatchReceiver is FirNoReceiverExpression -> {
|
||||
@@ -236,14 +242,18 @@ private fun FirCallableSymbol<*>.toSymbolForCall(
|
||||
declarationStorage.getIrPropertySymbol(this)
|
||||
} else {
|
||||
(fir as? FirSyntheticProperty)?.let { syntheticProperty ->
|
||||
val delegateSymbol = if (preferGetter) {
|
||||
syntheticProperty.getter.delegate.symbol
|
||||
if (isReference) {
|
||||
declarationStorage.getIrPropertySymbol(this, dispatchReceiverLookupTag)
|
||||
} else {
|
||||
syntheticProperty.setter?.delegate?.symbol
|
||||
?: throw AssertionError("Written synthetic property must have a setter")
|
||||
val delegateSymbol = if (preferGetter) {
|
||||
syntheticProperty.getter.delegate.symbol
|
||||
} else {
|
||||
syntheticProperty.setter?.delegate?.symbol
|
||||
?: throw AssertionError("Written synthetic property must have a setter")
|
||||
}
|
||||
delegateSymbol.unwrapCallRepresentative()
|
||||
.toSymbolForCall(dispatchReceiver, preferGetter, isDelegate = false)
|
||||
}
|
||||
delegateSymbol.unwrapCallRepresentative()
|
||||
.toSymbolForCall(dispatchReceiver, preferGetter, isDelegate = false)
|
||||
} ?: declarationStorage.getIrPropertySymbol(this)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -89,7 +89,8 @@ class CallAndReferenceGenerator(
|
||||
callableReferenceAccess.dispatchReceiver,
|
||||
conversionScope,
|
||||
explicitReceiver = callableReferenceAccess.explicitReceiver,
|
||||
isDelegate = isDelegate
|
||||
isDelegate = isDelegate,
|
||||
isReference = true
|
||||
)
|
||||
// val x by y ->
|
||||
// val `x$delegate` = y
|
||||
|
||||
+18
-6
@@ -44096,12 +44096,6 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/reflection/properties/noConflictOnKotlinGetterAndJavaField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideKotlinPropertyByJavaMethod.kt")
|
||||
public void testOverrideKotlinPropertyByJavaMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/properties/overrideKotlinPropertyByJavaMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("privateClassVal.kt")
|
||||
public void testPrivateClassVal() throws Exception {
|
||||
@@ -44168,6 +44162,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/reflection/properties/simpleGetProperties.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticJavaProperty.kt")
|
||||
public void testSyntheticJavaProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/properties/syntheticJavaProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("withLocalType.kt")
|
||||
public void testWithLocalType() throws Exception {
|
||||
@@ -48791,6 +48791,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/syntheticExtensions/implicitReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideKotlinPropertyByJavaMethod.kt")
|
||||
public void testOverrideKotlinPropertyByJavaMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticExtensions/overrideKotlinPropertyByJavaMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideOnlyGetter.kt")
|
||||
public void testOverrideOnlyGetter() throws Exception {
|
||||
@@ -48832,6 +48838,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
public void testSetterNonVoid2() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticExtensions/setterNonVoid2.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticJavaProperty.kt")
|
||||
public void testSyntheticJavaProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/syntheticExtensions/syntheticJavaProperty.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user