FIR: fix nullability loss on substitution
This commit is contained in:
committed by
Mikhail Glukhikh
parent
572c9e7115
commit
dae5822986
+1
-1
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -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])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user