FIR: use FROM_EXPRESSION, not FOR_SUBTYPING capt. types in substitution

This commit is contained in:
Mikhail Glukhikh
2020-09-17 17:38:44 +03:00
parent 86d1a3be37
commit 3c3aa3210e
4 changed files with 6 additions and 6 deletions
@@ -67,7 +67,7 @@ fun createSubstitution(
type: ConeClassLikeType,
session: FirSession
): Map<FirTypeParameterSymbol, ConeKotlinType> {
val capturedOrType = session.typeContext.captureFromArguments(type, CaptureStatus.FOR_SUBTYPING) ?: type
val capturedOrType = session.typeContext.captureFromArguments(type, CaptureStatus.FROM_EXPRESSION) ?: type
val typeArguments = (capturedOrType as ConeClassLikeType).typeArguments
return typeParameters.zip(typeArguments) { typeParameter, typeArgument ->
val typeParameterSymbol = typeParameter.symbol
@@ -151,7 +151,7 @@ data class ConeSubstitutorByMap(val substitution: Map<FirTypeParameterSymbol, Co
val session = type.lookupTag.symbol.fir.session
if (type.isUnsafeVarianceType(session)) {
return session.inferenceComponents.approximator.approximateToSuperType(
result, TypeApproximatorConfiguration.SubtypeCapturedTypesApproximation
result, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference
) as? ConeKotlinType ?: result
}
return result
@@ -132,13 +132,13 @@ class FirClassSubstitutionScope(
private fun ConeKotlinType.approximateCapturedCovariant(): ConeKotlinType {
return session.inferenceComponents.approximator.approximateToSuperType(
this, TypeApproximatorConfiguration.SubtypeCapturedTypesApproximation
this, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference
) as? ConeKotlinType ?: this
}
private fun ConeKotlinType.approximateCapturedContravariant(): ConeKotlinType {
return session.inferenceComponents.approximator.approximateToSubType(
this, TypeApproximatorConfiguration.SubtypeCapturedTypesApproximation
this, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference
) as? ConeKotlinType ?: this
}
@@ -19,7 +19,7 @@ fun foo2(a: A<out CharSequence>, b: A<in CharSequence>) {
a.foo1(Out())
a.foo1(Out<Nothing>())
a.<!INAPPLICABLE_CANDIDATE!>foo2<!>(Inv())
a.foo2(Inv())
a.<!INAPPLICABLE_CANDIDATE!>foo2<!>(Inv<CharSequence>())
a.<!INAPPLICABLE_CANDIDATE!>foo2<!><Inv<CharSequence>>(Inv())
@@ -31,7 +31,7 @@ fun foo2(a: A<out CharSequence>, b: A<in CharSequence>) {
b.foo1(Out<CharSequence>())
b.foo1<Out<CharSequence>>(Out())
b.<!INAPPLICABLE_CANDIDATE!>foo2<!>(Inv())
b.foo2(Inv())
b.<!INAPPLICABLE_CANDIDATE!>foo2<!>(Inv<CharSequence>())
b.<!INAPPLICABLE_CANDIDATE!>foo2<!><Inv<CharSequence>>(Inv())