@@ -169,8 +169,13 @@ class SwitchStatementMemberInfo<Node extends Object, Statement extends Node,
169169/// intermediate representation with each stack entry, and also record the kind
170170/// of each entry in order to verify that when an entity is popped, it has the
171171/// expected kind.
172- mixin TypeAnalyzer <Node extends Object , Statement extends Node ,
173- Expression extends Node , Variable extends Object , Type extends Object > {
172+ mixin TypeAnalyzer <
173+ Node extends Object ,
174+ Statement extends Node ,
175+ Expression extends Node ,
176+ Variable extends Object ,
177+ Type extends Object ,
178+ Pattern extends Node > {
174179 /// Returns the type `bool` .
175180 Type get boolType;
176181
@@ -180,7 +185,8 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
180185 /// Returns the type `dynamic` .
181186 Type get dynamicType;
182187
183- TypeAnalyzerErrors <Node , Statement , Expression , Variable , Type >? get errors;
188+ TypeAnalyzerErrors <Node , Statement , Expression , Variable , Type , Pattern >?
189+ get errors;
184190
185191 /// Returns the client's [FlowAnalysis] object.
186192 ///
@@ -213,9 +219,9 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
213219 /// Stack effect: pushes (Pattern innerPattern).
214220 void analyzeCastPattern (
215221 Type matchedType,
216- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
222+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
217223 MatchContext <Node , Expression > context,
218- Node innerPattern,
224+ Pattern innerPattern,
219225 Type type) {
220226 dispatchPattern (type, typeInfos, context, innerPattern);
221227 // Stack: (Pattern)
@@ -236,13 +242,13 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
236242 /// Stack effect: pushes (Expression).
237243 void analyzeConstantPattern (
238244 Type matchedType,
239- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
245+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
240246 MatchContext <Node , Expression > context,
241247 Node node,
242248 Expression expression) {
243249 // Stack: ()
244- TypeAnalyzerErrors <Node , Node , Expression , Variable , Type > ? errors =
245- this .errors;
250+ TypeAnalyzerErrors <Node , Node , Expression , Variable , Type , Pattern > ?
251+ errors = this .errors;
246252 Node ? irrefutableContext = context.irrefutableContext;
247253 if (irrefutableContext != null ) {
248254 errors? .refutablePatternInIrrefutableContext (node, irrefutableContext);
@@ -309,13 +315,18 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
309315 /// representation for `ifFalse` will be pushed by [handleNoStatement] . If
310316 /// there is no guard, the representation for `guard` will be pushed by
311317 /// [handleNoGuard] .
312- void analyzeIfCaseStatement (Statement node, Expression expression,
313- Node pattern, Expression ? guard, Statement ifTrue, Statement ? ifFalse) {
318+ void analyzeIfCaseStatement (
319+ Statement node,
320+ Expression expression,
321+ Pattern pattern,
322+ Expression ? guard,
323+ Statement ifTrue,
324+ Statement ? ifFalse) {
314325 // Stack: ()
315326 flow? .ifStatement_conditionBegin ();
316327 Type initializerType = analyzeExpression (expression, unknownType);
317328 // Stack: (Expression)
318- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos = {};
329+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos = {};
319330 // TODO(paulberry): rework handling of isFinal
320331 dispatchPattern (initializerType, typeInfos,
321332 new MatchContext (isFinal: false , topPattern: pattern), pattern);
@@ -365,7 +376,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
365376 ///
366377 /// Stack effect: pushes (Expression, Pattern).
367378 void analyzeInitializedVariableDeclaration (
368- Node node, Node pattern, Expression initializer,
379+ Node node, Pattern pattern, Expression initializer,
369380 {required bool isFinal, required bool isLate}) {
370381 // Stack: ()
371382 if (isLate && ! isVariablePattern (pattern)) {
@@ -380,7 +391,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
380391 if (isLate) {
381392 flow? .lateInitializer_end ();
382393 }
383- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos = {};
394+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos = {};
384395 dispatchPattern (
385396 initializerType,
386397 typeInfos,
@@ -415,9 +426,9 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
415426 /// Stack effect: pushes (n * Pattern) where n = elements.length.
416427 Type analyzeListPattern (
417428 Type matchedType,
418- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
429+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
419430 MatchContext <Node , Expression > context,
420- Node node,
431+ Pattern node,
421432 {Type ? elementType,
422433 required List <Node > elements}) {
423434 // Stack: ()
@@ -477,7 +488,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
477488 /// Stack effect: pushes (Pattern left, Pattern right)
478489 void analyzeLogicalPattern (
479490 Type matchedType,
480- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
491+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
481492 MatchContext <Node , Expression > context,
482493 Node node,
483494 Node lhs,
@@ -526,10 +537,10 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
526537 /// Stack effect: pushes (Pattern innerPattern).
527538 void analyzeNullCheckOrAssertPattern (
528539 Type matchedType,
529- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
540+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
530541 MatchContext <Node , Expression > context,
531542 Node node,
532- Node innerPattern,
543+ Pattern innerPattern,
533544 {required bool isAssert}) {
534545 // Stack: ()
535546 Type innerMatchedType = typeOperations.promoteToNonNull (matchedType);
@@ -548,7 +559,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
548559 /// a null-check or a null-assert pattern.
549560 ///
550561 /// Stack effect: none.
551- Type analyzeNullCheckOrAssertPatternSchema (Node innerPattern,
562+ Type analyzeNullCheckOrAssertPatternSchema (Pattern innerPattern,
552563 {required bool isAssert}) {
553564 if (isAssert) {
554565 return typeOperations.makeNullable (dispatchPatternSchema (innerPattern));
@@ -570,9 +581,9 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
570581 /// Stack effect: pushes (n * Pattern) where n = fields.length.
571582 Type analyzeRecordPattern (
572583 Type matchedType,
573- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
584+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
574585 MatchContext <Node , Expression > context,
575- Node node, {
586+ Pattern node, {
576587 required List <RecordPatternField <Node >> fields,
577588 }) {
578589 void dispatchField (RecordPatternField <Node > field, Type matchedType) {
@@ -675,14 +686,14 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
675686 /// Stack effect: pushes (Expression).
676687 void analyzeRelationalPattern (
677688 Type matchedType,
678- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
689+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
679690 MatchContext <Node , Expression > context,
680691 Node node,
681692 RelationalOperatorResolution <Type >? operator ,
682693 Expression operand) {
683694 // Stack: ()
684- TypeAnalyzerErrors <Node , Node , Expression , Variable , Type > ? errors =
685- this .errors;
695+ TypeAnalyzerErrors <Node , Node , Expression , Variable , Type , Pattern > ?
696+ errors = this .errors;
686697 Node ? irrefutableContext = context.irrefutableContext;
687698 if (irrefutableContext != null ) {
688699 errors? .refutablePatternInIrrefutableContext (node, irrefutableContext);
@@ -739,7 +750,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
739750 SwitchExpressionMemberInfo <Node , Expression > memberInfo =
740751 getSwitchExpressionMemberInfo (node, i);
741752 flow? .switchStatement_beginCase ();
742- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos = {};
753+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos = {};
743754 Node ? pattern = memberInfo.head.pattern;
744755 if (pattern != null ) {
745756 dispatchPattern (
@@ -800,7 +811,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
800811 // Stack: (Expression, numExecutionPaths * StatementCase)
801812 int firstCaseInThisExecutionPath = i;
802813 int numHeads = 0 ;
803- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos = {};
814+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos = {};
804815 flow? .switchStatement_beginCase ();
805816 flow? .switchStatement_beginAlternatives ();
806817 bool hasLabels = false ;
@@ -922,9 +933,9 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
922933 /// Stack effect: none.
923934 Type analyzeVariablePattern (
924935 Type matchedType,
925- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
936+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
926937 MatchContext <Node , Expression > context,
927- Node node,
938+ Pattern node,
928939 Variable ? variable,
929940 Type ? declaredType,
930941 {required bool isFinal}) {
@@ -1001,7 +1012,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
10011012 /// Stack effect: pushes (Pattern).
10021013 void dispatchPattern (
10031014 Type matchedType,
1004- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
1015+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
10051016 MatchContext <Node , Expression > context,
10061017 Node node);
10071018
@@ -1231,19 +1242,19 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
12311242 /// [staticType] , and reports any errors caused by type inconsistency.
12321243 /// [isImplicitlyTyped] indicates whether the variable is implicitly typed in
12331244 /// this pattern.
1234- bool _recordTypeInfo (Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
1235- {required Node pattern,
1245+ bool _recordTypeInfo (Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
1246+ {required Pattern pattern,
12361247 required Variable variable,
12371248 required Type staticType,
12381249 required bool isImplicitlyTyped}) {
1239- VariableTypeInfo <Node , Type >? typeInfo = typeInfos[variable];
1250+ VariableTypeInfo <Pattern , Type >? typeInfo = typeInfos[variable];
12401251 if (typeInfo == null ) {
12411252 typeInfos[variable] =
12421253 new VariableTypeInfo (pattern, staticType, isImplicitlyTyped);
12431254 return true ;
12441255 } else {
1245- TypeAnalyzerErrors <Node , Statement , Expression , Variable , Type > ? errors =
1246- this .errors;
1256+ TypeAnalyzerErrors <Node , Statement , Expression , Variable , Type , Pattern > ?
1257+ errors = this .errors;
12471258 if (errors != null ) {
12481259 if (! typeOperations.isSameType (
12491260 typeInfo._latestStaticType, staticType)) {
@@ -1272,7 +1283,8 @@ abstract class TypeAnalyzerErrors<
12721283 Statement extends Node ,
12731284 Expression extends Node ,
12741285 Variable extends Object ,
1275- Type extends Object > implements TypeAnalyzerErrorsBase {
1286+ Type extends Object ,
1287+ Pattern extends Node > implements TypeAnalyzerErrorsBase {
12761288 /// Called if [argument] has type [argumentType] , which is not assignable
12771289 /// to [parameterType] .
12781290 void argumentTypeNotAssignable ({
@@ -1299,9 +1311,9 @@ abstract class TypeAnalyzerErrors<
12991311 /// been inferred). [previousPattern] is the previous variable pattern that
13001312 /// was binding the same variable, and [previousType] is its type.
13011313 void inconsistentMatchVar (
1302- {required Node pattern,
1314+ {required Pattern pattern,
13031315 required Type type,
1304- required Node previousPattern,
1316+ required Pattern previousPattern,
13051317 required Type previousType});
13061318
13071319 /// Called if a single variable is bound both with an explicit type and with
@@ -1315,7 +1327,7 @@ abstract class TypeAnalyzerErrors<
13151327 /// TODO(paulberry): the spec might be changed so that this is not an error
13161328 /// condition. See https://github.com/dart-lang/language/issues/2424.
13171329 void inconsistentMatchVarExplicitness (
1318- {required Node pattern, required Node previousPattern});
1330+ {required Pattern pattern, required Node previousPattern});
13191331
13201332 /// Called if the static type of a condition is not assignable to `bool` .
13211333 void nonBooleanCondition (Expression node);
@@ -1336,7 +1348,7 @@ abstract class TypeAnalyzerErrors<
13361348 /// [matchedType] is the matched type, and [requiredType] is the required
13371349 /// type.
13381350 void patternTypeMismatchInIrrefutableContext (
1339- {required Node pattern,
1351+ {required Pattern pattern,
13401352 required Node context,
13411353 required Type matchedType,
13421354 required Type requiredType});
@@ -1394,8 +1406,8 @@ class TypeAnalyzerOptions {
13941406
13951407/// Data structure tracking information about the type of a variable bound by
13961408/// one or more patterns.
1397- class VariableTypeInfo <Node extends Object , Type extends Object > {
1398- Node _latestPattern;
1409+ class VariableTypeInfo <Pattern extends Object , Type extends Object > {
1410+ Pattern _latestPattern;
13991411
14001412 /// The static type of [_latestPattern] . This is used to detect
14011413 /// [TypeAnalyzerErrors.inconsistentMatchVar] .
0 commit comments