K2: Propagate explicit getter type to the property without initializer
In K1, we have the rules like: - if there's explicit type of a property, then use it - if there's an initializer, obtain its expression-type - Otherwise, use getter's return type The case when getter's type is implicit is handled at FirDeclarationsResolveTransformer.transformProperty ^KT-56707 Fixed
This commit is contained in:
committed by
Space Team
parent
c09607c791
commit
3f052af517
+12
-2
@@ -6,7 +6,9 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.copyWithNewSourceKind
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isFromVararg
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
@@ -154,8 +156,16 @@ open class FirTypeResolveTransformer(
|
||||
setAccessorTypesByPropertyType(property)
|
||||
}
|
||||
|
||||
if (property.returnTypeRef is FirResolvedTypeRef && property.delegate != null) {
|
||||
setAccessorTypesByPropertyType(property)
|
||||
when {
|
||||
property.returnTypeRef is FirResolvedTypeRef && property.delegate != null -> {
|
||||
setAccessorTypesByPropertyType(property)
|
||||
}
|
||||
property.returnTypeRef !is FirResolvedTypeRef && property.initializer == null &&
|
||||
property.getter?.returnTypeRef is FirResolvedTypeRef -> {
|
||||
property.replaceReturnTypeRef(
|
||||
property.getter!!.returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.PropertyTypeFromGetterReturnType)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
unboundCyclesInTypeParametersSupertypes(property)
|
||||
|
||||
Reference in New Issue
Block a user