Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: pkg/analyzer/lib/src/generated/static_type_analyzer.dart

Issue 2043173002: Fix LUB computation in face of errors in code (issue 26631) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/static_type_analyzer_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/static_type_analyzer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698