DelegatingDataFlowInfo: never store original type or its supertypes #KT-10666 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-01-21 17:03:14 +03:00
parent e04338f4fa
commit 2ee9f22242
@@ -219,7 +219,8 @@ internal class DelegatingDataFlowInfo private constructor(
if (getCollectedTypes(value).contains(type)) return this
if (!value.type.isFlexible() && value.type.isSubtypeOf(type)) return this
val newNullabilityInfo = if (type.isMarkedNullable) EMPTY_NULLABILITY_INFO else ImmutableMap.of(value, NOT_NULL)
val newTypeInfo = ImmutableSetMultimap.of(value, type)
val newTypeInfo = newTypeInfo()
newTypeInfo.put(value, type)
return create(this, newNullabilityInfo, newTypeInfo)
}
@@ -296,9 +297,20 @@ internal class DelegatingDataFlowInfo private constructor(
private fun create(parent: DataFlowInfo?,
nullabilityInfo: ImmutableMap<DataFlowValue, Nullability>,
// NB: typeInfo must be mutable here!
typeInfo: SetMultimap<DataFlowValue, KotlinType>,
valueWithGivenTypeInfo: DataFlowValue? = null
): DelegatingDataFlowInfo {
for (value in typeInfo.keys()) {
var iterator = typeInfo[value].iterator()
while (iterator.hasNext()) {
val type = iterator.next()
// Remove original type and for not flexible type also all its supertypes (see also KT-10666)
if (if (value.type.isFlexible()) value.type == type else value.type.isSubtypeOf(type)) {
iterator.remove()
}
}
}
return DelegatingDataFlowInfo(parent, nullabilityInfo, typeInfo, valueWithGivenTypeInfo)
}
}