OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:collection'; | 5 import 'dart:collection'; |
6 import 'package:analyzer/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
7 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 7 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
8 import 'package:analyzer/dart/ast/token.dart' show TokenType; | 8 import 'package:analyzer/dart/ast/token.dart' show TokenType; |
9 import 'package:analyzer/dart/ast/visitor.dart' show RecursiveAstVisitor; | 9 import 'package:analyzer/dart/ast/visitor.dart' show RecursiveAstVisitor; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 /// | 52 /// |
53 /// If [localIsNullable] is not supplied, this will use the known list of | 53 /// If [localIsNullable] is not supplied, this will use the known list of |
54 /// [_notNullLocals]. | 54 /// [_notNullLocals]. |
55 bool _isNullable(Expression expr, | 55 bool _isNullable(Expression expr, |
56 [bool localIsNullable(LocalVariableElement e)]) { | 56 [bool localIsNullable(LocalVariableElement e)]) { |
57 // TODO(jmesserly): we do recursive calls in a few places. This could | 57 // TODO(jmesserly): we do recursive calls in a few places. This could |
58 // leads to O(depth) cost for calling this function. We could store the | 58 // leads to O(depth) cost for calling this function. We could store the |
59 // resulting value if that becomes an issue, so we maintain the invariant | 59 // resulting value if that becomes an issue, so we maintain the invariant |
60 // that each node is visited once. | 60 // that each node is visited once. |
61 Element element = null; | 61 Element element = null; |
62 if (expr is PropertyAccess) { | 62 if (expr is PropertyAccess && |
| 63 expr.operator?.type != TokenType.QUESTION_PERIOD) { |
63 element = expr.propertyName.staticElement; | 64 element = expr.propertyName.staticElement; |
64 } else if (expr is Identifier) { | 65 } else if (expr is Identifier) { |
65 element = expr.staticElement; | 66 element = expr.staticElement; |
66 } | 67 } |
67 if (element != null) { | 68 if (element != null) { |
68 // Type literals are not null. | 69 // Type literals are not null. |
69 if (element is ClassElement || element is FunctionTypeAliasElement) { | 70 if (element is ClassElement || element is FunctionTypeAliasElement) { |
70 return false; | 71 return false; |
71 } | 72 } |
72 | 73 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 return false; | 328 return false; |
328 } | 329 } |
329 | 330 |
330 if (_nullInference._isNullable(right, visitLocal)) { | 331 if (_nullInference._isNullable(right, visitLocal)) { |
331 _nullableLocals.add(element); | 332 _nullableLocals.add(element); |
332 } | 333 } |
333 } | 334 } |
334 } | 335 } |
335 } | 336 } |
336 } | 337 } |
OLD | NEW |