Skip to content

Commit daa7f82

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[cfe] Capture argument via matchFutureOrType in constraint gathering
Part of #54902 Change-Id: I90f278fbe1ad4a58b779d0fc199c413e601bd4d6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358461 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent 8269f13 commit daa7f82

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

pkg/front_end/lib/src/fasta/type_inference/type_constraint_gatherer.dart

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -542,22 +542,20 @@ class TypeConstraintGatherer {
542542
// constraint set C. Or if P is a subtype match for Q0 under constraint set
543543
// C. Or if P is a subtype match for Future<Q0> under empty constraint set
544544
// C.
545-
if (typeOperations.matchFutureOr(q) != null) {
545+
if (typeOperations.matchFutureOr(q) case DartType q0?) {
546546
final int baseConstraintCount = _protoConstraints.length;
547547

548-
if (p is FutureOrType &&
549-
_isNullabilityAwareSubtypeMatch(
550-
p.typeArgument, (q as FutureOrType).typeArgument,
551-
constrainSupertype: constrainSupertype,
552-
treeNodeForTesting: treeNodeForTesting)) {
553-
return true;
548+
if (typeOperations.matchFutureOr(p) case DartType p0?) {
549+
if (_isNullabilityAwareSubtypeMatch(p0, q0,
550+
constrainSupertype: constrainSupertype,
551+
treeNodeForTesting: treeNodeForTesting)) {
552+
return true;
553+
}
554554
}
555555
_protoConstraints.length = baseConstraintCount;
556556

557557
bool isMatchWithFuture = _isNullabilityAwareSubtypeMatch(
558-
p,
559-
_environment.futureType(
560-
(q as FutureOrType).typeArgument, Nullability.nonNullable),
558+
p, _environment.futureType(q0, Nullability.nonNullable),
561559
constrainSupertype: constrainSupertype,
562560
treeNodeForTesting: treeNodeForTesting);
563561
bool matchWithFutureAddsConstraints =
@@ -567,7 +565,7 @@ class TypeConstraintGatherer {
567565
}
568566
_protoConstraints.length = baseConstraintCount;
569567

570-
if (_isNullabilityAwareSubtypeMatch(p, q.typeArgument,
568+
if (_isNullabilityAwareSubtypeMatch(p, q0,
571569
constrainSupertype: constrainSupertype,
572570
treeNodeForTesting: treeNodeForTesting)) {
573571
return true;
@@ -639,15 +637,13 @@ class TypeConstraintGatherer {
639637
//
640638
// If Future<P0> is a subtype match for Q under constraint set C1.
641639
// And if P0 is a subtype match for Q under constraint set C2.
642-
if (typeOperations.matchFutureOr(p) != null) {
640+
if (typeOperations.matchFutureOr(p) case DartType p0?) {
643641
final int baseConstraintCount = _protoConstraints.length;
644642
if (_isNullabilityAwareSubtypeMatch(
645-
_environment.futureType(
646-
(p as FutureOrType).typeArgument, Nullability.nonNullable),
647-
q,
643+
_environment.futureType(p0, Nullability.nonNullable), q,
648644
constrainSupertype: constrainSupertype,
649645
treeNodeForTesting: treeNodeForTesting) &&
650-
_isNullabilityAwareSubtypeMatch(p.typeArgument, q,
646+
_isNullabilityAwareSubtypeMatch(p0, q,
651647
constrainSupertype: constrainSupertype,
652648
treeNodeForTesting: treeNodeForTesting)) {
653649
return true;

0 commit comments

Comments
 (0)