checking subtype for invariant type with error generic argument may success

This commit is contained in:
Svetlana Isakova
2012-12-26 18:58:57 +04:00
parent 38cc3e39e4
commit 70cde87052
3 changed files with 20 additions and 1 deletions
@@ -197,7 +197,9 @@ public class TypeCheckingProcedure {
JetType superIn = getInType(parameter, superArgument);
JetType superOut = getOutType(parameter, superArgument);
if (parameter.getVariance() == INVARIANT && subArgument.getProjectionKind() == INVARIANT && superArgument.getProjectionKind() == INVARIANT) {
boolean argumentIsErrorType = ErrorUtils.isErrorType(subArgument.getType()) || ErrorUtils.isErrorType(superArgument.getType());
if (!argumentIsErrorType && parameter.getVariance() == INVARIANT
&& subArgument.getProjectionKind() == INVARIANT && superArgument.getProjectionKind() == INVARIANT) {
if (!constraints.assertEqualTypes(subArgument.getType(), superArgument.getType(), this)) return false;
}
else {
@@ -0,0 +1,12 @@
package a
fun foo<R> (f: ()->R, r: MutableList<R>) = r.add(f())
fun bar<R> (r: MutableList<R>, f: ()->R) = r.add(f())
fun test() {
val <!UNUSED_VARIABLE!>a<!> = <!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>foo<!>({1}, arrayListOf("")) //no type inference error on 'arrayListOf'
val <!UNUSED_VARIABLE!>b<!> = <!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>bar<!>(arrayListOf(""), {1})
}
// from standard library
fun arrayListOf<T>(vararg <!UNUSED_PARAMETER!>values<!>: T) : MutableList<T> {<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -2315,6 +2315,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt");
}
@TestMetadata("subtypeForInvariantWithErrorGenerics.kt")
public void testSubtypeForInvariantWithErrorGenerics() throws Exception {
doTest("compiler/testData/diagnostics/tests/inference/reportingImprovements/subtypeForInvariantWithErrorGenerics.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/inference/varargs")