@@ -219,7 +219,8 @@ internal class DelegatingDataFlowInfo private constructor(
219
219
if (getCollectedTypes(value).contains(type)) return this
220
220
if (! value.type.isFlexible() && value.type.isSubtypeOf(type)) return this
221
221
val newNullabilityInfo = if (type.isMarkedNullable) EMPTY_NULLABILITY_INFO else ImmutableMap .of(value, NOT_NULL )
222
- val newTypeInfo = ImmutableSetMultimap .of(value, type)
222
+ val newTypeInfo = newTypeInfo()
223
+ newTypeInfo.put(value, type)
223
224
return create(this , newNullabilityInfo, newTypeInfo)
224
225
}
225
226
@@ -296,9 +297,20 @@ internal class DelegatingDataFlowInfo private constructor(
296
297
297
298
private fun create (parent : DataFlowInfo ? ,
298
299
nullabilityInfo : ImmutableMap <DataFlowValue , Nullability >,
300
+ // NB: typeInfo must be mutable here!
299
301
typeInfo : SetMultimap <DataFlowValue , KotlinType >,
300
302
valueWithGivenTypeInfo : DataFlowValue ? = null
301
303
): DelegatingDataFlowInfo {
304
+ for (value in typeInfo.keys()) {
305
+ var iterator = typeInfo[value].iterator()
306
+ while (iterator.hasNext()) {
307
+ val type = iterator.next()
308
+ // Remove original type and for not flexible type also all its supertypes (see also KT-10666)
309
+ if (if (value.type.isFlexible()) value.type == type else value.type.isSubtypeOf(type)) {
310
+ iterator.remove()
311
+ }
312
+ }
313
+ }
302
314
return DelegatingDataFlowInfo (parent, nullabilityInfo, typeInfo, valueWithGivenTypeInfo)
303
315
}
304
316
}
0 commit comments