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

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

Issue 1823793002: Better casting of for-in loops. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Handle supertypes of Iterable and Stream. Created 4 years, 9 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/lib/src/task/strong/checker.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.error_verifier; 5 library analyzer.src.generated.error_verifier;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 5676 matching lines...) Expand 10 before | Expand all | Expand 10 after
5687 5687
5688 // Use an explicit string instead of [loopType] to remove the "<E>". 5688 // Use an explicit string instead of [loopType] to remove the "<E>".
5689 String loopTypeName = node.awaitKeyword != null ? "Stream" : "Iterable"; 5689 String loopTypeName = node.awaitKeyword != null ? "Stream" : "Iterable";
5690 5690
5691 // The object being iterated has to implement Iterable<T> for some T that 5691 // The object being iterated has to implement Iterable<T> for some T that
5692 // is assignable to the variable's type. 5692 // is assignable to the variable's type.
5693 // TODO(rnystrom): Move this into mostSpecificTypeArgument()? 5693 // TODO(rnystrom): Move this into mostSpecificTypeArgument()?
5694 iterableType = iterableType.resolveToBound(_typeProvider.objectType); 5694 iterableType = iterableType.resolveToBound(_typeProvider.objectType);
5695 DartType bestIterableType = 5695 DartType bestIterableType =
5696 _typeSystem.mostSpecificTypeArgument(iterableType, loopType); 5696 _typeSystem.mostSpecificTypeArgument(iterableType, loopType);
5697
5698 // Allow it to be a supertype of Iterable<T> (basically just Object) and do
5699 // an implicit downcast to Iterable<dynamic>.
5700 if (bestIterableType == null) {
5701 if (_typeSystem.isSubtypeOf(loopType, iterableType)) {
5702 bestIterableType = DynamicTypeImpl.instance;
5703 }
5704 }
5705
5697 if (bestIterableType == null) { 5706 if (bestIterableType == null) {
5698 _errorReporter.reportTypeErrorForNode( 5707 _errorReporter.reportTypeErrorForNode(
5699 StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE, 5708 StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE,
5700 node.iterable, 5709 node.iterable,
5701 [iterableType, loopTypeName]); 5710 [iterableType, loopTypeName]);
5702 } else if (!_typeSystem.isAssignableTo(bestIterableType, variableType)) { 5711 } else if (!_typeSystem.isAssignableTo(bestIterableType, variableType)) {
5703 _errorReporter.reportTypeErrorForNode( 5712 _errorReporter.reportTypeErrorForNode(
5704 StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE, 5713 StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE,
5705 node.iterable, 5714 node.iterable,
5706 [iterableType, loopTypeName, variableType]); 5715 [iterableType, loopTypeName, variableType]);
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
6314 class _InvocationCollector extends RecursiveAstVisitor { 6323 class _InvocationCollector extends RecursiveAstVisitor {
6315 final List<String> superCalls = <String>[]; 6324 final List<String> superCalls = <String>[];
6316 6325
6317 @override 6326 @override
6318 visitMethodInvocation(MethodInvocation node) { 6327 visitMethodInvocation(MethodInvocation node) {
6319 if (node.target is SuperExpression) { 6328 if (node.target is SuperExpression) {
6320 superCalls.add(node.methodName.name); 6329 superCalls.add(node.methodName.name);
6321 } 6330 }
6322 } 6331 }
6323 } 6332 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/strong/checker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698