NI: Fix smart-cast related regression
See the test and the issue for the clarification
After the change 7898922066
the expected type for "a" in expression "foo(a)" is A<E & B<*>>
But we have the original type A<E> and smart-casted enriched type A<B<*>>
(non of them is a subtype of A<E & B<*>>)
and fail in checkTypeInternal when checking types in during completion
^KT-35844 Fixed
This commit is contained in:
Generated
+5
@@ -11087,6 +11087,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3559.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt35844.kt")
|
||||
public void testKt35844() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt35844.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4420.kt")
|
||||
public void testKt4420() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt4420.kt");
|
||||
|
||||
+13
-1
@@ -34,7 +34,11 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.TypeIntersector
|
||||
import org.jetbrains.kotlin.types.checker.intersectTypes
|
||||
import org.jetbrains.kotlin.types.checker.intersectWrappedTypes
|
||||
import org.jetbrains.kotlin.types.typeUtil.expandIntersectionTypeIfNecessary
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
|
||||
class SmartCastManager(private val argumentTypeResolver: ArgumentTypeResolver) {
|
||||
@@ -134,7 +138,15 @@ class SmartCastManager(private val argumentTypeResolver: ArgumentTypeResolver) {
|
||||
else
|
||||
listOf(expectedType)
|
||||
|
||||
for (possibleType in c.dataFlowInfo.getCollectedTypes(dataFlowValue, c.languageVersionSettings)) {
|
||||
val collectedTypes = c.dataFlowInfo.getCollectedTypes(dataFlowValue, c.languageVersionSettings).toMutableList()
|
||||
|
||||
if (collectedTypes.isNotEmpty() && c.languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) {
|
||||
// Sometime expected type may be inferred to be an intersection of all of the smart-cast types
|
||||
val typeToIntersect = collectedTypes + dataFlowValue.type
|
||||
collectedTypes.addIfNotNull(intersectWrappedTypes(typeToIntersect))
|
||||
}
|
||||
|
||||
for (possibleType in collectedTypes) {
|
||||
if (expectedTypes.any { argumentTypeResolver.isSubtypeOfForArgumentType(possibleType, it) } &&
|
||||
(additionalPredicate == null || additionalPredicate(possibleType))
|
||||
) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// SKIP_TXT
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class A<X>
|
||||
|
||||
class B<T> {
|
||||
fun b(): T = TODO()
|
||||
}
|
||||
|
||||
fun <Y> foo(c: A<Y>): Y = TODO()
|
||||
|
||||
fun <E> main(a: A<E>) {
|
||||
a as A<B<*>>
|
||||
|
||||
foo(a).b()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// SKIP_TXT
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
class A<X>
|
||||
|
||||
class B<T> {
|
||||
fun b(): T = TODO()
|
||||
}
|
||||
|
||||
fun <Y> foo(c: A<Y>): Y = TODO()
|
||||
|
||||
fun <E> main(a: A<E>) {
|
||||
a <!UNCHECKED_CAST!>as A<B<*>><!>
|
||||
|
||||
foo(<!DEBUG_INFO_SMARTCAST!>a<!>).b()
|
||||
}
|
||||
@@ -11094,6 +11094,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3559.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt35844.kt")
|
||||
public void testKt35844() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt35844.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4420.kt")
|
||||
public void testKt4420() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt4420.kt");
|
||||
|
||||
Generated
+5
@@ -11089,6 +11089,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3559.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt35844.kt")
|
||||
public void testKt35844() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt35844.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt4420.kt")
|
||||
public void testKt4420() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt4420.kt");
|
||||
|
||||
Reference in New Issue
Block a user