FIR: determine synthetic accessor modality more precisely
Related to KT-47542
This commit is contained in:
+15
-5
@@ -68,6 +68,7 @@ class JavaClassUseSiteMemberScope(
|
|||||||
getterSymbol: FirNamedFunctionSymbol,
|
getterSymbol: FirNamedFunctionSymbol,
|
||||||
setterSymbol: FirNamedFunctionSymbol?,
|
setterSymbol: FirNamedFunctionSymbol?,
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
|
takeModalityFromGetter: Boolean,
|
||||||
): FirAccessorSymbol {
|
): FirAccessorSymbol {
|
||||||
return accessorByNameMap.getOrPut(property.name) {
|
return accessorByNameMap.getOrPut(property.name) {
|
||||||
buildSyntheticProperty {
|
buildSyntheticProperty {
|
||||||
@@ -79,7 +80,13 @@ class JavaClassUseSiteMemberScope(
|
|||||||
)
|
)
|
||||||
delegateGetter = getterSymbol.fir
|
delegateGetter = getterSymbol.fir
|
||||||
delegateSetter = setterSymbol?.fir
|
delegateSetter = setterSymbol?.fir
|
||||||
status = getterSymbol.fir.status.copy(newModality = chooseModalityForAccessor(property, delegateGetter))
|
status = getterSymbol.fir.status.copy(
|
||||||
|
newModality = if (takeModalityFromGetter) {
|
||||||
|
delegateGetter.modality ?: property.modality
|
||||||
|
} else {
|
||||||
|
chooseModalityForAccessor(property, delegateGetter)
|
||||||
|
}
|
||||||
|
)
|
||||||
deprecation = getDeprecationsFromAccessors(delegateGetter, delegateSetter, session.languageVersionSettings.apiVersion)
|
deprecation = getDeprecationsFromAccessors(delegateGetter, delegateSetter, session.languageVersionSettings.apiVersion)
|
||||||
}.symbol
|
}.symbol
|
||||||
}
|
}
|
||||||
@@ -118,8 +125,8 @@ class JavaClassUseSiteMemberScope(
|
|||||||
}
|
}
|
||||||
if (propertyFromSupertype !is FirPropertySymbol) continue
|
if (propertyFromSupertype !is FirPropertySymbol) continue
|
||||||
val overrideInClass =
|
val overrideInClass =
|
||||||
propertyFromSupertype.createOverridePropertyIfExists(declaredMemberScope)
|
propertyFromSupertype.createOverridePropertyIfExists(declaredMemberScope, takeModalityFromGetter = true)
|
||||||
?: propertyFromSupertype.createOverridePropertyIfExists(superTypesScope)
|
?: propertyFromSupertype.createOverridePropertyIfExists(superTypesScope, takeModalityFromGetter = false)
|
||||||
when {
|
when {
|
||||||
overrideInClass != null -> {
|
overrideInClass != null -> {
|
||||||
directOverriddenProperties.getOrPut(overrideInClass) { mutableListOf() }.add(propertyFromSupertype)
|
directOverriddenProperties.getOrPut(overrideInClass) { mutableListOf() }.add(propertyFromSupertype)
|
||||||
@@ -131,7 +138,10 @@ class JavaClassUseSiteMemberScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirVariableSymbol<*>.createOverridePropertyIfExists(scope: FirScope): FirPropertySymbol? {
|
private fun FirVariableSymbol<*>.createOverridePropertyIfExists(
|
||||||
|
scope: FirScope,
|
||||||
|
takeModalityFromGetter: Boolean
|
||||||
|
): FirPropertySymbol? {
|
||||||
if (this !is FirPropertySymbol) return null
|
if (this !is FirPropertySymbol) return null
|
||||||
val getterSymbol = this.findGetterOverride(scope) ?: return null
|
val getterSymbol = this.findGetterOverride(scope) ?: return null
|
||||||
val setterSymbol =
|
val setterSymbol =
|
||||||
@@ -141,7 +151,7 @@ class JavaClassUseSiteMemberScope(
|
|||||||
null
|
null
|
||||||
if (setterSymbol != null && setterSymbol.fir.modality != getterSymbol.fir.modality) return null
|
if (setterSymbol != null && setterSymbol.fir.modality != getterSymbol.fir.modality) return null
|
||||||
|
|
||||||
return generateAccessorSymbol(getterSymbol, setterSymbol, fir)
|
return generateAccessorSymbol(getterSymbol, setterSymbol, fir, takeModalityFromGetter)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirPropertySymbol.findGetterOverride(
|
private fun FirPropertySymbol.findGetterOverride(
|
||||||
|
|||||||
Vendored
-27
@@ -1,27 +0,0 @@
|
|||||||
// FULL_JDK
|
|
||||||
// ISSUE: KT-47542
|
|
||||||
|
|
||||||
// FILE: PlaceholderExceptionSupport.java
|
|
||||||
|
|
||||||
public interface PlaceholderExceptionSupport {
|
|
||||||
String getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// FILE: ExceptionWithAbstractMessage.java
|
|
||||||
|
|
||||||
public class ExceptionWithAbstractMessage extends RuntimeException implements PlaceholderExceptionSupport {
|
|
||||||
public ExceptionWithAbstractMessage(String x) { super(x); }
|
|
||||||
|
|
||||||
abstract String getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// FILE: PlaceholderException.java
|
|
||||||
|
|
||||||
public class PlaceholderException extends RuntimeException implements PlaceholderExceptionSupport {
|
|
||||||
public PlaceholderException(String x) { super(x); }
|
|
||||||
}
|
|
||||||
|
|
||||||
// FILE: main.kt
|
|
||||||
class KotlinTestSuccess : PlaceholderException("OK") {}
|
|
||||||
|
|
||||||
class KotlinTestFailure : ExceptionWithAbstractMessage("FAIL") {}
|
|
||||||
Vendored
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// FULL_JDK
|
// FULL_JDK
|
||||||
// ISSUE: KT-47542
|
// ISSUE: KT-47542
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user