[NI] More accurate handle of capture types from subtyping
#KT-31520 Fixed
This commit is contained in:
+5
@@ -10014,6 +10014,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/constraints"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("constraintFromVariantTypeWithNestedProjection.kt")
|
||||
public void testConstraintFromVariantTypeWithNestedProjection() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constraintOnFunctionLiteral.kt")
|
||||
public void testConstraintOnFunctionLiteral() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.kt");
|
||||
|
||||
+2
-2
@@ -181,7 +181,7 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val
|
||||
if (kind == UPPER) {
|
||||
val subType =
|
||||
typeApproximator.approximateToSubType(type, TypeApproximatorConfiguration.SubtypeCapturedTypesApproximation)
|
||||
if (subType != null && !subType.typeConstructor().isNothingConstructor()) {
|
||||
if (subType != null) {
|
||||
targetType = subType
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val
|
||||
if (kind == LOWER) {
|
||||
val superType =
|
||||
typeApproximator.approximateToSuperType(type, TypeApproximatorConfiguration.SubtypeCapturedTypesApproximation)
|
||||
if (superType != null && !superType.typeConstructor().isAnyConstructor()) { // todo rethink error reporting for Any cases
|
||||
if (superType != null) { // todo rethink error reporting for Any cases
|
||||
targetType = superType
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
fun <T> foo(array: Array<Array<T>>): Array<Array<T>> = array
|
||||
|
||||
fun test(array: Array<Array<out Int>>) {
|
||||
<!OI;TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>foo<!>(<!NI;NEW_INFERENCE_ERROR!>array<!>)
|
||||
<!OI;TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>foo<!>(<!NI;TYPE_MISMATCH!>array<!>)
|
||||
|
||||
val f: Array<out Array<out Int>> = <!OI;TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>foo<!>(<!NI;NEW_INFERENCE_ERROR, OI;TYPE_MISMATCH!>array<!>)
|
||||
val f: Array<out Array<out Int>> = <!OI;TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>foo<!>(<!TYPE_MISMATCH!>array<!>)
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -11,8 +11,8 @@ fun bar(b: B<in A<out Number>>, bOut: B<out A<out Number>>, bOut2: B<out A<Numbe
|
||||
foo(b)
|
||||
foo<Number>(b)
|
||||
|
||||
<!OI;TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>baz<!>(<!NI;NEW_INFERENCE_ERROR!>bOut<!>)
|
||||
baz<Number>(<!NI;NEW_INFERENCE_ERROR, OI;TYPE_MISMATCH!>bOut<!>)
|
||||
<!OI;TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>baz<!>(<!NI;TYPE_MISMATCH!>bOut<!>)
|
||||
baz<Number>(<!TYPE_MISMATCH!>bOut<!>)
|
||||
|
||||
baz(bOut2)
|
||||
baz<Number>(bOut2)
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// !WITH_NEW_INFERENCE
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Out<out T>
|
||||
class In<in T>
|
||||
class Inv<T>
|
||||
|
||||
fun <R> choose1(c: Out<Out<R>>) {}
|
||||
fun <R> choose2(c: In<In<R>>) {}
|
||||
fun <R> choose3(c: Inv<Inv<R>>) {}
|
||||
|
||||
fun f(o: Out<Out<*>>, i: In<In<*>>, inv: Inv<Inv<*>>) {
|
||||
choose1(o)
|
||||
<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>choose2<!>(i)
|
||||
<!OI;TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR!>choose3<!>(<!NI;TYPE_MISMATCH!>inv<!>)
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package
|
||||
|
||||
public fun </*0*/ R> choose1(/*0*/ c: Out<Out<R>>): kotlin.Unit
|
||||
public fun </*0*/ R> choose2(/*0*/ c: In<In<R>>): kotlin.Unit
|
||||
public fun </*0*/ R> choose3(/*0*/ c: Inv<Inv<R>>): kotlin.Unit
|
||||
public fun f(/*0*/ o: Out<Out<*>>, /*1*/ i: In<In<*>>, /*2*/ inv: Inv<Inv<*>>): kotlin.Unit
|
||||
|
||||
public final class In</*0*/ in T> {
|
||||
public constructor In</*0*/ in T>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class Inv</*0*/ T> {
|
||||
public constructor Inv</*0*/ T>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class Out</*0*/ out T> {
|
||||
public constructor Out</*0*/ out T>()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -10021,6 +10021,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/constraints"), Pattern.compile("^(.*)\\.kts?$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("constraintFromVariantTypeWithNestedProjection.kt")
|
||||
public void testConstraintFromVariantTypeWithNestedProjection() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constraintOnFunctionLiteral.kt")
|
||||
public void testConstraintOnFunctionLiteral() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.kt");
|
||||
|
||||
Generated
+5
@@ -10016,6 +10016,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/constraints"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("constraintFromVariantTypeWithNestedProjection.kt")
|
||||
public void testConstraintFromVariantTypeWithNestedProjection() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintFromVariantTypeWithNestedProjection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constraintOnFunctionLiteral.kt")
|
||||
public void testConstraintOnFunctionLiteral() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/constraints/constraintOnFunctionLiteral.kt");
|
||||
|
||||
Reference in New Issue
Block a user