[cfe] Generate covariant checks in pattern matching
Closes #52192 Change-Id: Iaac816273fb80eaf166fc300b2b3367f1a592d3f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302223 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
This commit is contained in:
committed by
Commit Queue
parent
4af8469493
commit
9b42e2d166
@@ -1088,6 +1088,11 @@ class NamedPattern extends Pattern {
|
||||
/// This is set during inference.
|
||||
DartType? resultType;
|
||||
|
||||
/// When used in an object pattern, this is set to `true` if the field value
|
||||
/// needs to be checked against the [resultType]. This is needed for fields
|
||||
/// whose type contain covariant types that occur in non-covariant positions.
|
||||
bool checkReturn = false;
|
||||
|
||||
/// When used in an object pattern, this holds the record on which the
|
||||
/// property for this pattern is read.
|
||||
///
|
||||
|
||||
@@ -4917,6 +4917,9 @@ class EquivalenceStrategy {
|
||||
if (!checkNamedPattern_resultType(visitor, node, other)) {
|
||||
result = visitor.resultOnInequivalence;
|
||||
}
|
||||
if (!checkNamedPattern_checkReturn(visitor, node, other)) {
|
||||
result = visitor.resultOnInequivalence;
|
||||
}
|
||||
if (!checkNamedPattern_recordType(visitor, node, other)) {
|
||||
result = visitor.resultOnInequivalence;
|
||||
}
|
||||
@@ -9149,6 +9152,12 @@ class EquivalenceStrategy {
|
||||
return visitor.checkNodes(node.resultType, other.resultType, 'resultType');
|
||||
}
|
||||
|
||||
bool checkNamedPattern_checkReturn(
|
||||
EquivalenceVisitor visitor, NamedPattern node, NamedPattern other) {
|
||||
return visitor.checkValues(
|
||||
node.checkReturn, other.checkReturn, 'checkReturn');
|
||||
}
|
||||
|
||||
bool checkNamedPattern_recordType(
|
||||
EquivalenceVisitor visitor, NamedPattern node, NamedPattern other) {
|
||||
return visitor.checkNodes(node.recordType, other.recordType, 'recordType');
|
||||
|
||||
Reference in New Issue
Block a user