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

Side by Side Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 2477093002: fix #27766, allow implicit casts from dynamic to composite types (Closed)
Patch Set: add changelog Created 4 years, 1 month 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 | « CHANGELOG.md ('k') | pkg/analyzer/test/src/task/strong/checker_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) 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 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be 5 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be
6 // refactored to fit into analyzer. 6 // refactored to fit into analyzer.
7 library analyzer.src.task.strong.checker; 7 library analyzer.src.task.strong.checker;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 // This cast is (probably) due to our different treatment of dynamic. 1081 // This cast is (probably) due to our different treatment of dynamic.
1082 // It may be more likely to fail at runtime. 1082 // It may be more likely to fail at runtime.
1083 if (from is InterfaceType) { 1083 if (from is InterfaceType) {
1084 // For class types, we'd like to allow non-generic down casts, e.g., 1084 // For class types, we'd like to allow non-generic down casts, e.g.,
1085 // Iterable<T> to List<T>. The intuition here is that raw (generic) 1085 // Iterable<T> to List<T>. The intuition here is that raw (generic)
1086 // casts are problematic, and we should complain about those. 1086 // casts are problematic, and we should complain about those.
1087 var typeArgs = from.typeArguments; 1087 var typeArgs = from.typeArguments;
1088 downCastComposite = 1088 downCastComposite =
1089 typeArgs.isEmpty || typeArgs.any((t) => t.isDynamic); 1089 typeArgs.isEmpty || typeArgs.any((t) => t.isDynamic);
1090 } else { 1090 } else {
1091 downCastComposite = true; 1091 downCastComposite = !from.isDynamic;
1092 } 1092 }
1093 } 1093 }
1094 1094
1095 var parent = expr.parent; 1095 var parent = expr.parent;
1096 ErrorCode errorCode; 1096 ErrorCode errorCode;
1097 if (downCastComposite) { 1097 if (downCastComposite) {
1098 errorCode = StrongModeCode.DOWN_CAST_COMPOSITE; 1098 errorCode = StrongModeCode.DOWN_CAST_COMPOSITE;
1099 } else if (from.isDynamic) { 1099 } else if (from.isDynamic) {
1100 errorCode = StrongModeCode.DYNAMIC_CAST; 1100 errorCode = StrongModeCode.DYNAMIC_CAST;
1101 } else if (parent is VariableDeclaration && parent.initializer == expr) { 1101 } else if (parent is VariableDeclaration && parent.initializer == expr) {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 var visited = new Set<InterfaceType>(); 1477 var visited = new Set<InterfaceType>();
1478 do { 1478 do {
1479 visited.add(current); 1479 visited.add(current);
1480 current.mixins.reversed.forEach( 1480 current.mixins.reversed.forEach(
1481 (m) => _checkIndividualOverridesFromClass(node, m, seen, true)); 1481 (m) => _checkIndividualOverridesFromClass(node, m, seen, true));
1482 _checkIndividualOverridesFromClass(node, current.superclass, seen, true); 1482 _checkIndividualOverridesFromClass(node, current.superclass, seen, true);
1483 current = current.superclass; 1483 current = current.superclass;
1484 } while (!current.isObject && !visited.contains(current)); 1484 } while (!current.isObject && !visited.contains(current));
1485 } 1485 }
1486 } 1486 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pkg/analyzer/test/src/task/strong/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698