FE1.0 Analysis API: fix getReturnTypeForKtDeclaration for setter parameter

This commit is contained in:
Tianyu Geng
2021-11-18 15:06:17 -08:00
committed by Ilya Kirillov
parent f1d0791f15
commit 6e555e1d28
3 changed files with 26 additions and 19 deletions
@@ -99,6 +99,22 @@ class KtFe10ExpressionTypeProvider(
return kotlinType.toKtType(analysisContext)
}
// Manually handle custom setter parameter
if (declaration is KtParameter) {
val parameterList = declaration.parent as? KtParameterList
if (parameterList?.parameters?.singleOrNull() == declaration) {
val propertyAccessor = parameterList.parent as? KtPropertyAccessor
val property = propertyAccessor?.parent as? KtProperty
if (property != null && property.setter == propertyAccessor) {
val bindingContext = analysisContext.analyze(property)
val kotlinType = bindingContext[BindingContext.VARIABLE, property]?.returnType
?: ErrorUtils.createErrorType("Return type for property \"${declaration.name}\" cannot be resolved")
return kotlinType.toKtType(analysisContext)
}
}
}
return analysisContext.builtIns.unitType.toKtType(analysisContext)
}