OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer.src.generated.static_type_analyzer; | 5 library analyzer.src.generated.static_type_analyzer; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 contextType.element == _typeProvider.listType.element) { | 655 contextType.element == _typeProvider.listType.element) { |
656 _resolver.inferenceContext.recordInference(node, contextType); | 656 _resolver.inferenceContext.recordInference(node, contextType); |
657 _recordStaticType(node, contextType); | 657 _recordStaticType(node, contextType); |
658 return null; | 658 return null; |
659 } | 659 } |
660 | 660 |
661 // If we don't have a type from the context, try to infer from the | 661 // If we don't have a type from the context, try to infer from the |
662 // elements | 662 // elements |
663 if (node.elements.isNotEmpty) { | 663 if (node.elements.isNotEmpty) { |
664 // Infer the list type from the arguments. | 664 // Infer the list type from the arguments. |
665 DartType staticType = | 665 Iterable<DartType> types = node.elements.map((e) => e.staticType).where(
(t) => t != null); |
666 node.elements.map((e) => e.staticType).reduce(_leastUpperBound); | 666 if (types.isEmpty) { |
| 667 return null; |
| 668 } |
| 669 DartType staticType = types.reduce(_leastUpperBound); |
667 if (staticType.isBottom) { | 670 if (staticType.isBottom) { |
668 staticType = _dynamicType; | 671 staticType = _dynamicType; |
669 } | 672 } |
670 DartType listLiteralType = | 673 DartType listLiteralType = |
671 _typeProvider.listType.instantiate(<DartType>[staticType]); | 674 _typeProvider.listType.instantiate(<DartType>[staticType]); |
672 if (!staticType.isDynamic) { | 675 if (!staticType.isDynamic) { |
673 _resolver.inferenceContext.recordInference(node, listLiteralType); | 676 _resolver.inferenceContext.recordInference(node, listLiteralType); |
674 } | 677 } |
675 _recordStaticType(node, listLiteralType); | 678 _recordStaticType(node, listLiteralType); |
676 return null; | 679 return null; |
(...skipping 1596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2273 } | 2276 } |
2274 // merge types | 2277 // merge types |
2275 if (result == null) { | 2278 if (result == null) { |
2276 result = type; | 2279 result = type; |
2277 } else { | 2280 } else { |
2278 result = _typeSystem.getLeastUpperBound(_typeProvider, result, type); | 2281 result = _typeSystem.getLeastUpperBound(_typeProvider, result, type); |
2279 } | 2282 } |
2280 return null; | 2283 return null; |
2281 } | 2284 } |
2282 } | 2285 } |
OLD | NEW |