@@ -39,12 +39,8 @@ class IntTypeAnalysisResult<Type extends Object>
39
39
}
40
40
41
41
/// Information about the code context surrounding a pattern match.
42
- class MatchContext <Node extends Object , Expression extends Node > {
43
- /// Simple case where the match context is non-final and there's nothing else
44
- /// special going on.
45
- static const MatchContext <Never , Never > simpleNonFinal =
46
- const MatchContext (isFinal: false , topPattern: null );
47
-
42
+ class MatchContext <Node extends Object , Expression extends Node ,
43
+ Pattern extends Node , Type extends Object , Variable extends Object > {
48
44
/// If non-`null` , the match is being done in an irrefutable context, and this
49
45
/// is the surrounding AST node that establishes the irrefutable context.
50
46
final Node ? irrefutableContext;
@@ -67,43 +63,45 @@ class MatchContext<Node extends Object, Expression extends Node> {
67
63
/// statement or switch expression.
68
64
final Expression ? _switchScrutinee;
69
65
66
+ /// A data structure keeping track of the variable patterns seen so far and
67
+ /// their type information.
68
+ final Map <Variable , VariableTypeInfo <Pattern , Type >> typeInfos;
69
+
70
70
const MatchContext (
71
71
{Expression ? initializer,
72
72
this .irrefutableContext,
73
73
required this .isFinal,
74
74
this .isLate = false ,
75
75
Expression ? switchScrutinee,
76
- required this .topPattern})
76
+ required this .topPattern,
77
+ required this .typeInfos})
77
78
: _initializer = initializer,
78
79
_switchScrutinee = switchScrutinee;
79
80
80
81
/// If the pattern [pattern] is the [topPattern] and there is a corresponding
81
82
/// initializer expression, returns it. Otherwise returns `null` .
82
- ///
83
- /// Note: the type of [pattern] is `Object` to avoid a runtime covariance
84
- /// check (which would fail if this method is called on [simpleNonFinal] ).
85
- Expression ? getInitializer (Object pattern) =>
83
+ Expression ? getInitializer (Pattern pattern) =>
86
84
identical (pattern, topPattern) ? _initializer : null ;
87
85
88
86
/// If the pattern [pattern] is the [topPattern] and there is a corresponding
89
87
/// switch scrutinee expression, returns it. Otherwise returns `null` .
90
- ///
91
- /// Note: the type of [pattern] is `Object` to avoid a runtime covariance
92
- /// check (which would fail if this method is called on [simpleNonFinal] ).
93
- Expression ? getSwitchScrutinee (Object pattern) =>
88
+ Expression ? getSwitchScrutinee (Node pattern) =>
94
89
identical (pattern, topPattern) ? _switchScrutinee : null ;
95
90
96
91
/// Returns a modified version of `this` , with [irrefutableContext] set to
97
92
/// `null` . This is used to suppress cascading errors after reporting
98
93
/// [TypeAnalyzerErrors.refutablePatternInIrrefutableContext] .
99
- MatchContext <Node , Expression > makeRefutable () => irrefutableContext == null
100
- ? this
101
- : new MatchContext (
102
- initializer: _initializer,
103
- isFinal: isFinal,
104
- isLate: isLate,
105
- switchScrutinee: _switchScrutinee,
106
- topPattern: topPattern);
94
+ MatchContext <Node , Expression , Pattern , Type , Variable > makeRefutable () =>
95
+ irrefutableContext == null
96
+ ? this
97
+ : new MatchContext (
98
+ initializer: _initializer,
99
+ isFinal: isFinal,
100
+ isLate: isLate,
101
+ switchScrutinee: _switchScrutinee,
102
+ topPattern: topPattern,
103
+ typeInfos: typeInfos,
104
+ );
107
105
}
108
106
109
107
/// Container for the result of running type analysis on an expression that does
0 commit comments