Revert "Issue 43162. Change matching dynamic/void vs. 'T?'."

This reverts commit 7b0aeb2ac8.

Reason for revert: regressions in analysis in legacy mode, see b/168675476

Original change's description:
> Issue 43162. Change matching dynamic/void vs. 'T?'.
> 
> Bug: https://github.com/dart-lang/sdk/issues/43162
> Change-Id: I8ae2166e4bc593b42ddd39c35e7d02a706d7b94d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162621
> Reviewed-by: Leaf Petersen <leafp@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>

TBR=leafp@google.com,scheglov@google.com,brianwilkerson@google.com,srawlins@google.com

Change-Id: I288f8ccf82c17565c40e02245998590ebd7c98bc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/43162
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162747
Reviewed-by: David Morgan <davidmorgan@google.com>
Commit-Queue: David Morgan <davidmorgan@google.com>
This commit is contained in:
David Morgan 2020-09-16 07:36:05 +00:00 committed by commit-bot@chromium.org
parent 13aaaae1b2
commit 8d8df2c9f6
4 changed files with 4 additions and 76 deletions

View file

@ -139,19 +139,10 @@ class TypeConstraintGatherer {
// If `Q` is a legacy type `Q0*` then the match holds under constraint
// set `C`:
// Only if `P` is a subtype match for `Q?` under constraint set `C`.
if (Q_nullability == NullabilitySuffix.star) {
if (identical(P, DynamicTypeImpl.instance) ||
identical(P, VoidTypeImpl.instance)) {
// If `P` is `dynamic` or `void` and `P` is a subtype match
// for `Q0` under constraint set `C`.
var Q0 = (Q as TypeImpl).withNullability(NullabilitySuffix.none);
return trySubtypeMatch(P, Q0, leftSchema);
} else {
// Or if `P` is not `dynamic` or `void` and `P` is a subtype match
// for `Q0?` under constraint set `C`.
var Qq = (Q as TypeImpl).withNullability(NullabilitySuffix.question);
return trySubtypeMatch(P, Qq, leftSchema);
}
var Qq = (Q as TypeImpl).withNullability(NullabilitySuffix.question);
return trySubtypeMatch(P, Qq, leftSchema);
}
// If `Q` is `FutureOr<Q0>` the match holds under constraint set `C`:
@ -210,16 +201,6 @@ class TypeConstraintGatherer {
_constraints.length = rewind;
}
// Or if `P` is `dynamic` or `void` and `Object` is a subtype match
// for `Q0` under constraint set `C`.
if (identical(P, DynamicTypeImpl.instance) ||
identical(P, VoidTypeImpl.instance)) {
if (trySubtypeMatch(_typeSystem.objectNone, Q0, leftSchema)) {
return true;
}
_constraints.length = rewind;
}
// Or if `P` is a subtype match for `Q0` under non-empty
// constraint set `C`.
var P_matches_Q0 = trySubtypeMatch(P, Q0, leftSchema);

View file

@ -841,29 +841,6 @@ class TypeConstraintGathererTest extends AbstractTypeSystemNullSafetyTest {
_checkMatch([T], numStar, T_star, true, ['num <: T <: _']);
}
/// If `Q` is a legacy type `Q0*` then the match holds under constraint
/// set `C`:
/// If `P` is `dynamic` or `void` and `P` is a subtype match for `Q0`
/// under constraint set `C`.
test_left_top_right_legacy() {
var U = typeParameter('U', bound: objectNone);
var U_star = typeParameterTypeStar(U);
_checkMatch([U], dynamicNone, U_star, false, ['dynamic <: U <: _']);
_checkMatch([U], voidNone, U_star, false, ['void <: U <: _']);
}
/// If `Q` is `Q0?` the match holds under constraint set `C`:
/// Or if `P` is `dynamic` or `void` and `Object` is a subtype match
/// for `Q0` under constraint set `C`.
test_left_top_right_nullable() {
var U = typeParameter('U', bound: objectNone);
var U_question = typeParameterTypeQuestion(U);
_checkMatch([U], dynamicNone, U_question, false, ['Object <: U <: _']);
_checkMatch([U], voidNone, U_question, false, ['Object <: U <: _']);
}
/// If `P` is a type variable `X` in `L`, then the match holds:
/// Under constraint `_ <: X <: Q`.
test_left_typeParameter() {

View file

@ -2600,34 +2600,4 @@ main() {
assertType(findNode.cascade('A()'), 'A');
}
test_typeArgumentTypes_generic_inferred_leftTop_dynamic() async {
await assertNoErrorsInCode('''
void foo<T extends Object>(T? value) {}
void f(dynamic o) {
foo(o);
}
''');
assertTypeArgumentTypes(
findNode.methodInvocation('foo(o)'),
['Object'],
);
}
test_typeArgumentTypes_generic_inferred_leftTop_void() async {
await assertNoErrorsInCode('''
void foo<T extends Object>(List<T?> value) {}
void f(List<void> o) {
foo(o);
}
''');
assertTypeArgumentTypes(
findNode.methodInvocation('foo(o)'),
['Object'],
);
}
}

View file

@ -55,7 +55,7 @@ main() {
var c = C.list(o);
var f = bar(o);
var l = o.whereNotNull();
var l = o.whereNotNull;
c.expectStaticType<Exactly<C<Object>>>();
Expect.type<C<Object>>(c); // Run-time type is subtype of C<Object>.