FIR: Fix another inconsistency with FE1.0 in synthetic properties resolution

This commit is contained in:
Denis.Zharkov
2021-10-22 14:28:58 +03:00
parent fe1b4d61c2
commit 52c2908bb7
8 changed files with 67 additions and 119 deletions
@@ -11,8 +11,7 @@ import org.jetbrains.kotlin.name.Name
abstract class FirSyntheticNamesProvider : FirSessionComponent {
abstract fun possibleGetterNamesByPropertyName(name: Name): List<Name>
abstract fun setterNameByGetterName(name: Name): Name?
abstract fun getterNameBySetterName(name: Name): Name?
abstract fun setterNameByGetterName(name: Name): Name
abstract fun possiblePropertyNamesByAccessorName(name: Name): List<Name>
}
@@ -85,33 +85,31 @@ class FirSyntheticPropertiesScope(
var matchingSetter: FirSimpleFunction? = null
if (getterReturnType != null) {
val setterName = syntheticNamesProvider.setterNameByGetterName(getterName)
if (setterName != null) {
baseScope.processFunctionsByName(setterName, fun(setterSymbol: FirFunctionSymbol<*>) {
if (matchingSetter != null) return
val setter = setterSymbol.fir as? FirSimpleFunction ?: return
val parameter = setter.valueParameters.singleOrNull() ?: return
if (setter.typeParameters.isNotEmpty() || setter.isStatic) return
val parameterType = (parameter.returnTypeRef as? FirResolvedTypeRef)?.type ?: return
// TODO: at this moment it works for cases like
// class Base {
// void setSomething(Object value) {}
// }
// class Derived extends Base {
// String getSomething() { return ""; }
// }
// In FE 1.0, we should have also Object getSomething() in class Base for this to work
// I think details here are worth designing
if (!AbstractTypeChecker.isSubtypeOf(
session.typeContext,
getterReturnType.withNullability(NOT_NULL, session.typeContext),
parameterType.withNullability(NOT_NULL, session.typeContext)
)
) {
return
}
matchingSetter = setter
})
}
baseScope.processFunctionsByName(setterName, fun(setterSymbol: FirFunctionSymbol<*>) {
if (matchingSetter != null) return
val setter = setterSymbol.fir as? FirSimpleFunction ?: return
val parameter = setter.valueParameters.singleOrNull() ?: return
if (setter.typeParameters.isNotEmpty() || setter.isStatic) return
val parameterType = (parameter.returnTypeRef as? FirResolvedTypeRef)?.type ?: return
// TODO: at this moment it works for cases like
// class Base {
// void setSomething(Object value) {}
// }
// class Derived extends Base {
// String getSomething() { return ""; }
// }
// In FE 1.0, we should have also Object getSomething() in class Base for this to work
// I think details here are worth designing
if (!AbstractTypeChecker.isSubtypeOf(
session.typeContext,
getterReturnType.withNullability(NOT_NULL, session.typeContext),
parameterType.withNullability(NOT_NULL, session.typeContext)
)
) {
return
}
matchingSetter = setter
})
}
val classLookupTag = getterSymbol.originalOrSelf().dispatchReceiverClassOrNull()