NI: Fix type mismatch caused by smartcast
^KT-25434 Fixed
This commit is contained in:
Generated
+5
@@ -10023,6 +10023,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/starApproximationFlexible.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/starApproximationFlexible.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("tooEagerSmartcast.kt")
|
||||||
|
public void testTooEagerSmartcast() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("tryNumberLowerBoundsBeforeUpperBounds.kt")
|
@TestMetadata("tryNumberLowerBoundsBeforeUpperBounds.kt")
|
||||||
public void testTryNumberLowerBoundsBeforeUpperBounds() throws Exception {
|
public void testTryNumberLowerBoundsBeforeUpperBounds() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.kt");
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// SKIP_TXT
|
||||||
|
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
|
||||||
|
interface OutBase<out E>
|
||||||
|
interface OutDerived<out F> : OutBase<F>
|
||||||
|
|
||||||
|
fun <X> OutBase<X>.myLast(): X = TODO()
|
||||||
|
|
||||||
|
fun <T> foo(x: OutBase<T>) {
|
||||||
|
if (x is OutDerived<*>) {
|
||||||
|
val l: T = x.myLast() // required T, found Cap(*). Only in NI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface InvBase<E>
|
||||||
|
interface InvDerived<F> : InvBase<F>
|
||||||
|
|
||||||
|
fun <X> InvBase<X>.myLastInv(): X = TODO()
|
||||||
|
|
||||||
|
fun <T> fooInv(x: InvBase<T>) {
|
||||||
|
if (x is InvDerived<*>) {
|
||||||
|
val l: T = x.<!INAPPLICABLE_CANDIDATE!>myLastInv<!>() // required T, found Cap(*). Only in NI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Base<E>
|
||||||
|
|
||||||
|
fun <Q> Base<Q>.foo(): Q = TODO()
|
||||||
|
fun <Q : CharSequence> Base<Q>.baz(): Q = TODO()
|
||||||
|
|
||||||
|
interface Derived<F : CharSequence> : Base<F>
|
||||||
|
|
||||||
|
fun Number.num() {}
|
||||||
|
|
||||||
|
fun main(b: Base<out Number>) {
|
||||||
|
b.foo().num()
|
||||||
|
if (b is Derived<*>) {
|
||||||
|
b.<!INAPPLICABLE_CANDIDATE!>foo<!>().num()
|
||||||
|
b.<!INAPPLICABLE_CANDIDATE!>baz<!>().<!UNRESOLVED_REFERENCE!>length<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// SKIP_TXT
|
||||||
|
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
|
||||||
|
interface OutBase<out E>
|
||||||
|
interface OutDerived<out F> : OutBase<F>
|
||||||
|
|
||||||
|
fun <X> OutBase<X>.myLast(): X = TODO()
|
||||||
|
|
||||||
|
fun <T> foo(x: OutBase<T>) {
|
||||||
|
if (x is OutDerived<*>) {
|
||||||
|
val l: T = x.myLast() // required T, found Cap(*). Only in NI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface InvBase<E>
|
||||||
|
interface InvDerived<F> : InvBase<F>
|
||||||
|
|
||||||
|
fun <X> InvBase<X>.myLastInv(): X = TODO()
|
||||||
|
|
||||||
|
fun <T> fooInv(x: InvBase<T>) {
|
||||||
|
if (x is InvDerived<*>) {
|
||||||
|
val l: T = x.myLastInv() // required T, found Cap(*). Only in NI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Base<E>
|
||||||
|
|
||||||
|
fun <Q> Base<Q>.foo(): Q = TODO()
|
||||||
|
fun <Q : CharSequence> Base<Q>.baz(): Q = TODO()
|
||||||
|
|
||||||
|
interface Derived<F : CharSequence> : Base<F>
|
||||||
|
|
||||||
|
fun Number.num() {}
|
||||||
|
|
||||||
|
fun main(b: Base<out Number>) {
|
||||||
|
b.foo().num()
|
||||||
|
if (b is Derived<*>) {
|
||||||
|
b.foo().num()
|
||||||
|
b.baz().length
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10030,6 +10030,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/starApproximationFlexible.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/starApproximationFlexible.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("tooEagerSmartcast.kt")
|
||||||
|
public void testTooEagerSmartcast() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("tryNumberLowerBoundsBeforeUpperBounds.kt")
|
@TestMetadata("tryNumberLowerBoundsBeforeUpperBounds.kt")
|
||||||
public void testTryNumberLowerBoundsBeforeUpperBounds() throws Exception {
|
public void testTryNumberLowerBoundsBeforeUpperBounds() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.kt");
|
||||||
|
|||||||
Generated
+5
@@ -10025,6 +10025,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/starApproximationFlexible.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/starApproximationFlexible.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("tooEagerSmartcast.kt")
|
||||||
|
public void testTooEagerSmartcast() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("tryNumberLowerBoundsBeforeUpperBounds.kt")
|
@TestMetadata("tryNumberLowerBoundsBeforeUpperBounds.kt")
|
||||||
public void testTryNumberLowerBoundsBeforeUpperBounds() throws Exception {
|
public void testTryNumberLowerBoundsBeforeUpperBounds() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/tryNumberLowerBoundsBeforeUpperBounds.kt");
|
||||||
|
|||||||
@@ -269,8 +269,6 @@ object AbstractTypeChecker {
|
|||||||
1 -> return isSubtypeForSameConstructor(supertypesWithSameConstructor.first().asArgumentList(), superType)
|
1 -> return isSubtypeForSameConstructor(supertypesWithSameConstructor.first().asArgumentList(), superType)
|
||||||
|
|
||||||
else -> { // at least 2 supertypes with same constructors. Such case is rare
|
else -> { // at least 2 supertypes with same constructors. Such case is rare
|
||||||
if (supertypesWithSameConstructor.any { isSubtypeForSameConstructor(it.asArgumentList(), superType) }) return true
|
|
||||||
|
|
||||||
val newArguments = ArgumentList(superConstructor.parametersCount())
|
val newArguments = ArgumentList(superConstructor.parametersCount())
|
||||||
for (index in 0 until superConstructor.parametersCount()) {
|
for (index in 0 until superConstructor.parametersCount()) {
|
||||||
val allProjections = supertypesWithSameConstructor.map {
|
val allProjections = supertypesWithSameConstructor.map {
|
||||||
@@ -283,7 +281,9 @@ object AbstractTypeChecker {
|
|||||||
newArguments.add(intersection)
|
newArguments.add(intersection)
|
||||||
}
|
}
|
||||||
|
|
||||||
return isSubtypeForSameConstructor(newArguments, superType)
|
if (isSubtypeForSameConstructor(newArguments, superType)) return true
|
||||||
|
|
||||||
|
return supertypesWithSameConstructor.any { isSubtypeForSameConstructor(it.asArgumentList(), superType) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user