FIR: fix nullability loss on substitution

This commit is contained in:
Simon Ogorodnik
2019-04-17 17:58:55 +03:00
committed by Mikhail Glukhikh
parent 572c9e7115
commit dae5822986
2 changed files with 8 additions and 2 deletions
@@ -271,7 +271,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext,
TypeSubstitutorMarker {
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
val new = map[type.typeConstructor()] ?: return null
return new as ConeKotlinType
return makeNullableIfNeed(type.isMarkedNullable, new as ConeKotlinType)
}
}
}
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.resolve.substitution
import org.jetbrains.kotlin.fir.resolve.withNullability
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeAbbreviatedTypeImpl
@@ -44,6 +45,11 @@ abstract class AbstractConeSubstitutor : ConeSubstitutor {
abstract fun substituteType(type: ConeKotlinType): ConeKotlinType?
fun makeNullableIfNeed(isNullable: Boolean, type: ConeKotlinType?): ConeKotlinType? {
if (!isNullable) return type
return type?.withNullability(ConeNullability.NULLABLE)
}
override fun substituteOrSelf(type: ConeKotlinType): ConeKotlinType {
return substituteOrNull(type) ?: type
}
@@ -124,6 +130,6 @@ class ConeSubstitutorByMap(val substitution: Map<ConeTypeParameterSymbol, ConeKo
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
if (type !is ConeTypeParameterType) return null
return substitution[type.lookupTag]
return makeNullableIfNeed(type.isMarkedNullable, substitution[type.lookupTag])
}
}