diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java index fd494689cbe..b151931d407 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.smartcasts; import com.google.common.collect.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.builtins.KotlinBuiltIns; +import org.jetbrains.kotlin.types.FlexibleTypesKt; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.types.TypeUtils; import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt; @@ -281,6 +281,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL public DataFlowInfo establishSubtyping(@NotNull DataFlowValue value, @NotNull KotlinType type) { if (value.getType().equals(type)) return this; if (getPossibleTypes(value).contains(type)) return this; + if (!FlexibleTypesKt.isFlexible(value.getType()) && TypeUtilsKt.isSubtypeOf(value.getType(), type)) return this; ImmutableMap newNullabilityInfo = type.isMarkedNullable() ? EMPTY_NULLABILITY_INFO : ImmutableMap.of(value, NOT_NULL); SetMultimap newTypeInfo = ImmutableSetMultimap.of(value, type); diff --git a/compiler/testData/diagnostics/tests/regressions/kt6508.kt b/compiler/testData/diagnostics/tests/regressions/kt6508.kt index 1e1e885f325..c01396408be 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt6508.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt6508.kt @@ -19,6 +19,6 @@ import foo.View fun String.gah(view:View ?) { if (view is TextView) - view + view else TextView() as foo.TextView } \ No newline at end of file