Skip to content

Commit

Permalink
FIR: resolve types in accessors when not resolving accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjeon authored and TeamCityServer committed Sep 24, 2021
1 parent c51d37d commit ad18343
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Expand Up @@ -77,6 +77,7 @@ internal class FirDesignatedImplicitTypesTransformerForIDE(
//Not resolved for some getters and setters #KT-46995
// check(declaration.getter?.returnTypeRef?.let { it is FirResolvedTypeRef } ?: true)
// check(declaration.setter?.returnTypeRef?.let { it is FirResolvedTypeRef } ?: true)
// check(declaration.setter?.valueParameters?.get(0)?.returnTypeRef?.let { it is FirResolvedTypeRef } ?: true)
}
else -> error("Unexpected type: ${declaration::class.simpleName}")
}
Expand Down
Expand Up @@ -170,6 +170,12 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
if (mayResolveSetter) FirPropertyBodyResolveState.EVERYTHING_RESOLVED
else FirPropertyBodyResolveState.INITIALIZER_AND_GETTER_RESOLVED
)
} else if (returnTypeRef is FirResolvedTypeRef) {
// Even though we're not going to resolve accessors themselves (so as to avoid resolve cycle, like KT-48634),
// we still need to resolve types in accessors (as per IMPLICIT_TYPES_BODY_RESOLVE contract).
property.getter?.transformTypeWithPropertyType(returnTypeRef)
property.setter?.transformTypeWithPropertyType(returnTypeRef)
property.setter?.transformReturnTypeRef(transformer, withExpectedType(session.builtinTypes.unitType.type))
}
}
}
Expand Down Expand Up @@ -343,18 +349,27 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
storeVariableReturnType(this)
enhancedTypeRef = returnTypeRef
// We need update type of getter for case when its type was approximated
getter?.replaceReturnTypeRef(enhancedTypeRef)
getter?.transformTypeWithPropertyType(enhancedTypeRef)
}
if (mayResolveSetter) {
setter?.let {
if (it.valueParameters[0].returnTypeRef is FirImplicitTypeRef) {
it.valueParameters[0].transformReturnTypeRef(StoreType, enhancedTypeRef)
}
setter?.let {
if (it.valueParameters[0].returnTypeRef is FirImplicitTypeRef) {
it.transformTypeWithPropertyType(enhancedTypeRef)
}
if (mayResolveSetter) {
transformAccessor(it, enhancedTypeRef, this)
}
}
}

private fun FirPropertyAccessor.transformTypeWithPropertyType(propertyTypeRef: FirTypeRef) {
when {
isGetter ->
replaceReturnTypeRef(propertyTypeRef)
isSetter ->
valueParameters[0].transformReturnTypeRef(StoreType, propertyTypeRef)
}
}

private fun transformAccessor(
accessor: FirPropertyAccessor,
enhancedTypeRef: FirTypeRef,
Expand Down

0 comments on commit ad18343

Please sign in to comment.