@@ -169,8 +169,13 @@ class SwitchStatementMemberInfo<Node extends Object, Statement extends Node,
169
169
/// intermediate representation with each stack entry, and also record the kind
170
170
/// of each entry in order to verify that when an entity is popped, it has the
171
171
/// 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 > {
174
179
/// Returns the type `bool` .
175
180
Type get boolType;
176
181
@@ -180,7 +185,8 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
180
185
/// Returns the type `dynamic` .
181
186
Type get dynamicType;
182
187
183
- TypeAnalyzerErrors <Node , Statement , Expression , Variable , Type >? get errors;
188
+ TypeAnalyzerErrors <Node , Statement , Expression , Variable , Type , Pattern >?
189
+ get errors;
184
190
185
191
/// Returns the client's [FlowAnalysis] object.
186
192
///
@@ -213,9 +219,9 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
213
219
/// Stack effect: pushes (Pattern innerPattern).
214
220
void analyzeCastPattern (
215
221
Type matchedType,
216
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
222
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
217
223
MatchContext <Node , Expression > context,
218
- Node innerPattern,
224
+ Pattern innerPattern,
219
225
Type type) {
220
226
dispatchPattern (type, typeInfos, context, innerPattern);
221
227
// Stack: (Pattern)
@@ -236,13 +242,13 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
236
242
/// Stack effect: pushes (Expression).
237
243
void analyzeConstantPattern (
238
244
Type matchedType,
239
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
245
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
240
246
MatchContext <Node , Expression > context,
241
247
Node node,
242
248
Expression expression) {
243
249
// Stack: ()
244
- TypeAnalyzerErrors <Node , Node , Expression , Variable , Type > ? errors =
245
- this .errors;
250
+ TypeAnalyzerErrors <Node , Node , Expression , Variable , Type , Pattern > ?
251
+ errors = this .errors;
246
252
Node ? irrefutableContext = context.irrefutableContext;
247
253
if (irrefutableContext != null ) {
248
254
errors? .refutablePatternInIrrefutableContext (node, irrefutableContext);
@@ -309,13 +315,18 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
309
315
/// representation for `ifFalse` will be pushed by [handleNoStatement] . If
310
316
/// there is no guard, the representation for `guard` will be pushed by
311
317
/// [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) {
314
325
// Stack: ()
315
326
flow? .ifStatement_conditionBegin ();
316
327
Type initializerType = analyzeExpression (expression, unknownType);
317
328
// Stack: (Expression)
318
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos = {};
329
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos = {};
319
330
// TODO(paulberry): rework handling of isFinal
320
331
dispatchPattern (initializerType, typeInfos,
321
332
new MatchContext (isFinal: false , topPattern: pattern), pattern);
@@ -365,7 +376,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
365
376
///
366
377
/// Stack effect: pushes (Expression, Pattern).
367
378
void analyzeInitializedVariableDeclaration (
368
- Node node, Node pattern, Expression initializer,
379
+ Node node, Pattern pattern, Expression initializer,
369
380
{required bool isFinal, required bool isLate}) {
370
381
// Stack: ()
371
382
if (isLate && ! isVariablePattern (pattern)) {
@@ -380,7 +391,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
380
391
if (isLate) {
381
392
flow? .lateInitializer_end ();
382
393
}
383
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos = {};
394
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos = {};
384
395
dispatchPattern (
385
396
initializerType,
386
397
typeInfos,
@@ -415,9 +426,9 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
415
426
/// Stack effect: pushes (n * Pattern) where n = elements.length.
416
427
Type analyzeListPattern (
417
428
Type matchedType,
418
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
429
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
419
430
MatchContext <Node , Expression > context,
420
- Node node,
431
+ Pattern node,
421
432
{Type ? elementType,
422
433
required List <Node > elements}) {
423
434
// Stack: ()
@@ -477,7 +488,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
477
488
/// Stack effect: pushes (Pattern left, Pattern right)
478
489
void analyzeLogicalPattern (
479
490
Type matchedType,
480
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
491
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
481
492
MatchContext <Node , Expression > context,
482
493
Node node,
483
494
Node lhs,
@@ -526,10 +537,10 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
526
537
/// Stack effect: pushes (Pattern innerPattern).
527
538
void analyzeNullCheckOrAssertPattern (
528
539
Type matchedType,
529
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
540
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
530
541
MatchContext <Node , Expression > context,
531
542
Node node,
532
- Node innerPattern,
543
+ Pattern innerPattern,
533
544
{required bool isAssert}) {
534
545
// Stack: ()
535
546
Type innerMatchedType = typeOperations.promoteToNonNull (matchedType);
@@ -548,7 +559,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
548
559
/// a null-check or a null-assert pattern.
549
560
///
550
561
/// Stack effect: none.
551
- Type analyzeNullCheckOrAssertPatternSchema (Node innerPattern,
562
+ Type analyzeNullCheckOrAssertPatternSchema (Pattern innerPattern,
552
563
{required bool isAssert}) {
553
564
if (isAssert) {
554
565
return typeOperations.makeNullable (dispatchPatternSchema (innerPattern));
@@ -570,9 +581,9 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
570
581
/// Stack effect: pushes (n * Pattern) where n = fields.length.
571
582
Type analyzeRecordPattern (
572
583
Type matchedType,
573
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
584
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
574
585
MatchContext <Node , Expression > context,
575
- Node node, {
586
+ Pattern node, {
576
587
required List <RecordPatternField <Node >> fields,
577
588
}) {
578
589
void dispatchField (RecordPatternField <Node > field, Type matchedType) {
@@ -675,14 +686,14 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
675
686
/// Stack effect: pushes (Expression).
676
687
void analyzeRelationalPattern (
677
688
Type matchedType,
678
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
689
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
679
690
MatchContext <Node , Expression > context,
680
691
Node node,
681
692
RelationalOperatorResolution <Type >? operator ,
682
693
Expression operand) {
683
694
// Stack: ()
684
- TypeAnalyzerErrors <Node , Node , Expression , Variable , Type > ? errors =
685
- this .errors;
695
+ TypeAnalyzerErrors <Node , Node , Expression , Variable , Type , Pattern > ?
696
+ errors = this .errors;
686
697
Node ? irrefutableContext = context.irrefutableContext;
687
698
if (irrefutableContext != null ) {
688
699
errors? .refutablePatternInIrrefutableContext (node, irrefutableContext);
@@ -739,7 +750,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
739
750
SwitchExpressionMemberInfo <Node , Expression > memberInfo =
740
751
getSwitchExpressionMemberInfo (node, i);
741
752
flow? .switchStatement_beginCase ();
742
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos = {};
753
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos = {};
743
754
Node ? pattern = memberInfo.head.pattern;
744
755
if (pattern != null ) {
745
756
dispatchPattern (
@@ -800,7 +811,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
800
811
// Stack: (Expression, numExecutionPaths * StatementCase)
801
812
int firstCaseInThisExecutionPath = i;
802
813
int numHeads = 0 ;
803
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos = {};
814
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos = {};
804
815
flow? .switchStatement_beginCase ();
805
816
flow? .switchStatement_beginAlternatives ();
806
817
bool hasLabels = false ;
@@ -922,9 +933,9 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
922
933
/// Stack effect: none.
923
934
Type analyzeVariablePattern (
924
935
Type matchedType,
925
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
936
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
926
937
MatchContext <Node , Expression > context,
927
- Node node,
938
+ Pattern node,
928
939
Variable ? variable,
929
940
Type ? declaredType,
930
941
{required bool isFinal}) {
@@ -1001,7 +1012,7 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
1001
1012
/// Stack effect: pushes (Pattern).
1002
1013
void dispatchPattern (
1003
1014
Type matchedType,
1004
- Map <Variable , VariableTypeInfo <Node , Type >> typeInfos,
1015
+ Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos,
1005
1016
MatchContext <Node , Expression > context,
1006
1017
Node node);
1007
1018
@@ -1231,19 +1242,19 @@ mixin TypeAnalyzer<Node extends Object, Statement extends Node,
1231
1242
/// [staticType] , and reports any errors caused by type inconsistency.
1232
1243
/// [isImplicitlyTyped] indicates whether the variable is implicitly typed in
1233
1244
/// 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,
1236
1247
required Variable variable,
1237
1248
required Type staticType,
1238
1249
required bool isImplicitlyTyped}) {
1239
- VariableTypeInfo <Node , Type >? typeInfo = typeInfos[variable];
1250
+ VariableTypeInfo <Pattern , Type >? typeInfo = typeInfos[variable];
1240
1251
if (typeInfo == null ) {
1241
1252
typeInfos[variable] =
1242
1253
new VariableTypeInfo (pattern, staticType, isImplicitlyTyped);
1243
1254
return true ;
1244
1255
} else {
1245
- TypeAnalyzerErrors <Node , Statement , Expression , Variable , Type > ? errors =
1246
- this .errors;
1256
+ TypeAnalyzerErrors <Node , Statement , Expression , Variable , Type , Pattern > ?
1257
+ errors = this .errors;
1247
1258
if (errors != null ) {
1248
1259
if (! typeOperations.isSameType (
1249
1260
typeInfo._latestStaticType, staticType)) {
@@ -1272,7 +1283,8 @@ abstract class TypeAnalyzerErrors<
1272
1283
Statement extends Node ,
1273
1284
Expression extends Node ,
1274
1285
Variable extends Object ,
1275
- Type extends Object > implements TypeAnalyzerErrorsBase {
1286
+ Type extends Object ,
1287
+ Pattern extends Node > implements TypeAnalyzerErrorsBase {
1276
1288
/// Called if [argument] has type [argumentType] , which is not assignable
1277
1289
/// to [parameterType] .
1278
1290
void argumentTypeNotAssignable ({
@@ -1299,9 +1311,9 @@ abstract class TypeAnalyzerErrors<
1299
1311
/// been inferred). [previousPattern] is the previous variable pattern that
1300
1312
/// was binding the same variable, and [previousType] is its type.
1301
1313
void inconsistentMatchVar (
1302
- {required Node pattern,
1314
+ {required Pattern pattern,
1303
1315
required Type type,
1304
- required Node previousPattern,
1316
+ required Pattern previousPattern,
1305
1317
required Type previousType});
1306
1318
1307
1319
/// Called if a single variable is bound both with an explicit type and with
@@ -1315,7 +1327,7 @@ abstract class TypeAnalyzerErrors<
1315
1327
/// TODO(paulberry): the spec might be changed so that this is not an error
1316
1328
/// condition. See https://github.com/dart-lang/language/issues/2424.
1317
1329
void inconsistentMatchVarExplicitness (
1318
- {required Node pattern, required Node previousPattern});
1330
+ {required Pattern pattern, required Node previousPattern});
1319
1331
1320
1332
/// Called if the static type of a condition is not assignable to `bool` .
1321
1333
void nonBooleanCondition (Expression node);
@@ -1336,7 +1348,7 @@ abstract class TypeAnalyzerErrors<
1336
1348
/// [matchedType] is the matched type, and [requiredType] is the required
1337
1349
/// type.
1338
1350
void patternTypeMismatchInIrrefutableContext (
1339
- {required Node pattern,
1351
+ {required Pattern pattern,
1340
1352
required Node context,
1341
1353
required Type matchedType,
1342
1354
required Type requiredType});
@@ -1394,8 +1406,8 @@ class TypeAnalyzerOptions {
1394
1406
1395
1407
/// Data structure tracking information about the type of a variable bound by
1396
1408
/// 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;
1399
1411
1400
1412
/// The static type of [_latestPattern] . This is used to detect
1401
1413
/// [TypeAnalyzerErrors.inconsistentMatchVar] .
0 commit comments