@@ -187,6 +187,14 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
187
187
/// A function parameter is always initialized, so [initialized] is `true` .
188
188
void declare (Variable variable, bool initialized);
189
189
190
+ /// Call this method after visiting a variable pattern in a non-assignment
191
+ /// context (or a wildcard pattern).
192
+ ///
193
+ /// [matchedType] should be the static type of the value being matched.
194
+ /// [staticType] should be the static type of the variable pattern itself.
195
+ void declaredVariablePattern (
196
+ {required Type matchedType, required Type staticType});
197
+
190
198
/// Call this method before visiting the body of a "do-while" statement.
191
199
/// [doStatement] should be the same node that was passed to
192
200
/// [AssignedVariables.endNode] for the do-while statement.
@@ -518,6 +526,15 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
518
526
void parenthesizedExpression (
519
527
Expression outerExpression, Expression innerExpression);
520
528
529
+ /// Call this method just after visiting the right hand side of a pattern
530
+ /// assignment expression, and before visiting the pattern.
531
+ ///
532
+ /// [rhs] is the right hand side expression.
533
+ void patternAssignment_afterRhs (Expression rhs);
534
+
535
+ /// Call this method after visiting a pattern assignment expression.
536
+ void patternAssignment_end ();
537
+
521
538
/// Call this method just after visiting the initializer of a pattern variable
522
539
/// declaration, and before visiting the pattern.
523
540
void patternVariableDeclaration_afterInitializer (Expression initializer);
@@ -746,12 +763,6 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
746
763
/// statement.
747
764
void tryFinallyStatement_finallyBegin (Node body);
748
765
749
- /// Call this method after visiting a variable pattern.
750
- ///
751
- /// [matchedType] should be the static type of the value being matched.
752
- /// [staticType] should be the static type of the variable pattern itself.
753
- void variablePattern ({required Type matchedType, required Type staticType});
754
-
755
766
/// Call this method when encountering an expression that reads the value of
756
767
/// a variable.
757
768
///
@@ -950,6 +961,16 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
950
961
() => _wrapped.declare (variable, initialized));
951
962
}
952
963
964
+ @override
965
+ void declaredVariablePattern (
966
+ {required Type matchedType, required Type staticType}) {
967
+ _wrap (
968
+ 'declaredVariablePattern(matchedType: $matchedType , '
969
+ 'staticType: $staticType )' ,
970
+ () => _wrapped.declaredVariablePattern (
971
+ matchedType: matchedType, staticType: staticType));
972
+ }
973
+
953
974
@override
954
975
void doStatement_bodyBegin (Statement doStatement) {
955
976
return _wrap ('doStatement_bodyBegin($doStatement )' ,
@@ -1243,6 +1264,17 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
1243
1264
_wrapped.parenthesizedExpression (outerExpression, innerExpression));
1244
1265
}
1245
1266
1267
+ @override
1268
+ void patternAssignment_afterRhs (Expression rhs) {
1269
+ _wrap ('patternAssignment_afterRhs($rhs )' ,
1270
+ () => _wrapped.patternAssignment_afterRhs (rhs));
1271
+ }
1272
+
1273
+ @override
1274
+ void patternAssignment_end () {
1275
+ _wrap ('patternAssignment_end()' , () => _wrapped.patternAssignment_end ());
1276
+ }
1277
+
1246
1278
@override
1247
1279
void patternVariableDeclaration_afterInitializer (Expression initializer) {
1248
1280
_wrap (
@@ -1405,14 +1437,6 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
1405
1437
() => _wrapped.tryFinallyStatement_finallyBegin (body));
1406
1438
}
1407
1439
1408
- @override
1409
- void variablePattern ({required Type matchedType, required Type staticType}) {
1410
- _wrap (
1411
- 'variablePattern(matchedType: $matchedType , staticType: $staticType )' ,
1412
- () => _wrapped.variablePattern (
1413
- matchedType: matchedType, staticType: staticType));
1414
- }
1415
-
1416
1440
@override
1417
1441
Type ? variableRead (Expression expression, Variable variable) {
1418
1442
return _wrap ('variableRead($expression , $variable )' ,
@@ -3371,6 +3395,25 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
3371
3395
promotionKeyStore.keyForVariable (variable), initialized);
3372
3396
}
3373
3397
3398
+ @override
3399
+ void declaredVariablePattern (
3400
+ {required Type matchedType, required Type staticType}) {
3401
+ _PatternContext <Type > context = _stack.last as _PatternContext <Type >;
3402
+ ReferenceWithType <Type >? scrutineeReference = context._scrutineeReference;
3403
+ bool coversMatchedType =
3404
+ typeOperations.isSubtypeOf (matchedType, staticType);
3405
+ if (scrutineeReference != null ) {
3406
+ ExpressionInfo <Type > promotionInfo =
3407
+ _current.tryPromoteForTypeCheck (this , scrutineeReference, staticType);
3408
+ _current = promotionInfo.ifTrue;
3409
+ if (! coversMatchedType) {
3410
+ context._unmatched = _join (context._unmatched, promotionInfo.ifFalse);
3411
+ }
3412
+ } else if (! coversMatchedType) {
3413
+ context._unmatched = _join (context._unmatched, _current);
3414
+ }
3415
+ }
3416
+
3374
3417
@override
3375
3418
void doStatement_bodyBegin (Statement doStatement) {
3376
3419
AssignedVariablesNodeInfo info =
@@ -3848,6 +3891,16 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
3848
3891
forwardExpression (outerExpression, innerExpression);
3849
3892
}
3850
3893
3894
+ @override
3895
+ void patternAssignment_afterRhs (Expression rhs) {
3896
+ _pushPattern (_getExpressionReference (rhs));
3897
+ }
3898
+
3899
+ @override
3900
+ void patternAssignment_end () {
3901
+ _popPattern (null );
3902
+ }
3903
+
3851
3904
@override
3852
3905
void patternVariableDeclaration_afterInitializer (Expression initializer) {
3853
3906
_pushPattern (_getExpressionReference (initializer));
@@ -4048,24 +4101,6 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
4048
4101
context._beforeFinally = _current;
4049
4102
}
4050
4103
4051
- @override
4052
- void variablePattern ({required Type matchedType, required Type staticType}) {
4053
- _PatternContext <Type > context = _stack.last as _PatternContext <Type >;
4054
- ReferenceWithType <Type >? scrutineeReference = context._scrutineeReference;
4055
- bool coversMatchedType =
4056
- typeOperations.isSubtypeOf (matchedType, staticType);
4057
- if (scrutineeReference != null ) {
4058
- ExpressionInfo <Type > promotionInfo =
4059
- _current.tryPromoteForTypeCheck (this , scrutineeReference, staticType);
4060
- _current = promotionInfo.ifTrue;
4061
- if (! coversMatchedType) {
4062
- context._unmatched = _join (context._unmatched, promotionInfo.ifFalse);
4063
- }
4064
- } else if (! coversMatchedType) {
4065
- context._unmatched = _join (context._unmatched, _current);
4066
- }
4067
- }
4068
-
4069
4104
@override
4070
4105
Type ? variableRead (Expression expression, Variable variable) {
4071
4106
int variableKey = promotionKeyStore.keyForVariable (variable);
@@ -4510,6 +4545,10 @@ class _LegacyTypePromotion<Node extends Object, Statement extends Node,
4510
4545
@override
4511
4546
void declare (Variable variable, bool initialized) {}
4512
4547
4548
+ @override
4549
+ void declaredVariablePattern (
4550
+ {required Type matchedType, required Type staticType}) {}
4551
+
4513
4552
@override
4514
4553
void doStatement_bodyBegin (Statement doStatement) {}
4515
4554
@@ -4778,6 +4817,12 @@ class _LegacyTypePromotion<Node extends Object, Statement extends Node,
4778
4817
forwardExpression (outerExpression, innerExpression);
4779
4818
}
4780
4819
4820
+ @override
4821
+ void patternAssignment_afterRhs (Expression rhs) {}
4822
+
4823
+ @override
4824
+ void patternAssignment_end () {}
4825
+
4781
4826
@override
4782
4827
void patternVariableDeclaration_afterInitializer (Expression initializer) {}
4783
4828
@@ -4858,9 +4903,6 @@ class _LegacyTypePromotion<Node extends Object, Statement extends Node,
4858
4903
@override
4859
4904
void tryFinallyStatement_finallyBegin (Node body) {}
4860
4905
4861
- @override
4862
- void variablePattern ({required Type matchedType, required Type staticType}) {}
4863
-
4864
4906
@override
4865
4907
Type ? variableRead (Expression expression, Variable variable) {
4866
4908
int variableKey = _promotionKeyStore.keyForVariable (variable);
0 commit comments