44
55import 'package:analyzer/dart/ast/ast.dart' ;
66import 'package:analyzer/dart/ast/standard_ast_factory.dart' ;
7- import 'package:analyzer/dart/ast/token.dart' ;
87import 'package:analyzer/dart/ast/visitor.dart' ;
98import 'package:analyzer/dart/element/element.dart' ;
109import 'package:analyzer/dart/element/type.dart' ;
@@ -23,7 +22,7 @@ class FlowAnalysisHelper {
2322 final NodeOperations <Expression > _nodeOperations;
2423
2524 /// The reused instance for creating new [FlowAnalysis] instances.
26- final TypeOperations < VariableElement , DartType > _typeOperations;
25+ final _TypeSystemTypeOperations _typeOperations;
2726
2827 /// Precomputed sets of potentially assigned variables.
2928 final AssignedVariables <Statement , VariableElement > assignedVariables;
@@ -58,23 +57,14 @@ class FlowAnalysisHelper {
5857
5958 var left = node.leftHandSide;
6059
61- VariableElement localElement;
6260 if (left is SimpleIdentifier ) {
6361 var element = left.staticElement;
6462 if (element is VariableElement ) {
65- localElement = element;
63+ return element;
6664 }
6765 }
6866
69- // Not assignment to a local variable.
70- if (localElement == null ) return null ;
71-
72- var isCompound = node.operator .type != TokenType .EQ ;
73- if (isCompound) {
74- flow.read (localElement);
75- }
76-
77- return localElement;
67+ return null ;
7868 }
7969
8070 void assignmentExpression_afterRight (
@@ -165,11 +155,6 @@ class FlowAnalysisHelper {
165155 return ;
166156 }
167157
168- for (var variable in flow.readBeforeWritten) {
169- assert (variable is LocalVariableElement );
170- result.readBeforeWritten.add (variable);
171- }
172-
173158 if (! flow.isReachable) {
174159 result.functionBodiesThatDontComplete.add (node);
175160 }
@@ -235,17 +220,32 @@ class FlowAnalysisHelper {
235220 }
236221 }
237222
223+ bool isPotentiallyNonNullableLocalReadBeforeWrite (SimpleIdentifier node) {
224+ if (flow == null ) return false ;
225+
226+ if (node.inDeclarationContext ()) return false ;
227+ if (! node.inGetterContext ()) return false ;
228+
229+ var element = node.staticElement;
230+ if (element is LocalVariableElement ) {
231+ if (element.isLate) return false ;
232+
233+ var typeSystem = _typeOperations.typeSystem;
234+ if (typeSystem.isPotentiallyNonNullable (element.type)) {
235+ return ! flow.isAssigned (element);
236+ }
237+ }
238+
239+ return false ;
240+ }
241+
238242 void simpleIdentifier (SimpleIdentifier node) {
239243 if (flow == null ) return ;
240244
241245 var element = node.staticElement;
242246 var isLocalVariable = element is LocalVariableElement ;
243247 if (isLocalVariable || element is ParameterElement ) {
244248 if (node.inGetterContext () && ! node.inDeclarationContext ()) {
245- if (isLocalVariable) {
246- flow.read (element);
247- }
248-
249249 if (flow.isNullable (element)) {
250250 result.nullableNodes.add (node);
251251 }
@@ -334,8 +334,6 @@ class FlowAnalysisHelper {
334334class FlowAnalysisResult {
335335 static const _astKey = 'FlowAnalysisResult' ;
336336
337- final List <LocalVariableElement > readBeforeWritten = [];
338-
339337 /// The list of identifiers, resolved to a local variable or a parameter,
340338 /// where the variable is known to be nullable.
341339 final List <SimpleIdentifier > nullableNodes = [];
0 commit comments