Skip to content

Commit 2ee9f22

Browse files
committed
DelegatingDataFlowInfo: never store original type or its supertypes #KT-10666 Fixed
1 parent e04338f commit 2ee9f22

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ internal class DelegatingDataFlowInfo private constructor(
219219
if (getCollectedTypes(value).contains(type)) return this
220220
if (!value.type.isFlexible() && value.type.isSubtypeOf(type)) return this
221221
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)
223224
return create(this, newNullabilityInfo, newTypeInfo)
224225
}
225226

@@ -296,9 +297,20 @@ internal class DelegatingDataFlowInfo private constructor(
296297

297298
private fun create(parent: DataFlowInfo?,
298299
nullabilityInfo: ImmutableMap<DataFlowValue, Nullability>,
300+
// NB: typeInfo must be mutable here!
299301
typeInfo: SetMultimap<DataFlowValue, KotlinType>,
300302
valueWithGivenTypeInfo: DataFlowValue? = null
301303
): 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+
}
302314
return DelegatingDataFlowInfo(parent, nullabilityInfo, typeInfo, valueWithGivenTypeInfo)
303315
}
304316
}

0 commit comments

Comments
 (0)