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

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

Issue 1823793002: Better casting of for-in loops. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: 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
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 /// Defines static information collected by the type checker and used later by 5 /// Defines static information collected by the type checker and used later by
6 /// emitters to generate code. 6 /// emitters to generate code.
7 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be 7 // TODO(jmesserly): this was ported from package:dev_compiler, and needs to be
8 // refactored to fit into analyzer. 8 // refactored to fit into analyzer.
9 library analyzer.src.task.strong.info; 9 library analyzer.src.task.strong.info;
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 } 61 }
62 62
63 /// Base class for all casts from base type to sub type. 63 /// Base class for all casts from base type to sub type.
64 abstract class DownCast extends CoercionInfo { 64 abstract class DownCast extends CoercionInfo {
65 final DartType _fromType; 65 final DartType _fromType;
66 final DartType _toType; 66 final DartType _toType;
67 67
68 DownCast._internal( 68 DownCast._internal(
69 TypeSystem rules, Expression expression, this._fromType, this._toType) 69 TypeSystem rules, Expression expression, this._fromType, this._toType)
70 : super(rules, expression) { 70 : super(rules, expression);
71 assert(_toType != baseType &&
72 _fromType == baseType &&
73 (baseType.isDynamic ||
74 // Call methods make the following non-redundant.
75 _toType.isSubtypeOf(baseType) ||
76 baseType.isAssignableTo(_toType)));
77 }
78 71
79 @override 72 @override
80 List<Object> get arguments => [baseType, convertedType]; 73 List<Object> get arguments => [baseType, convertedType];
81 74
75 /// The type being cast from.
76 ///
77 /// This is usually the static type of the associated expression, but may not
78 /// be if the cast is attached to a variable in a for-in loop.
79 @override
80 DartType get baseType => _fromType;
81
82 DartType get convertedType => _toType; 82 DartType get convertedType => _toType;
83 83
84 @override 84 @override
85 String get message => 'Unsound implicit cast from {0} to {1}'; 85 String get message => 'Unsound implicit cast from {0} to {1}';
86 86
87 // Factory to create correct DownCast variant. 87 /// Factory to create correct DownCast variant.
88 static StaticInfo create(StrongTypeSystemImpl rules, Expression expression, 88 static StaticInfo create(StrongTypeSystemImpl rules, Expression expression,
89 DartType fromType, DartType toType) { 89 DartType fromType, DartType toType) {
90 // toT <:_R fromT => to <: fromT 90 // toT <:_R fromT => to <: fromT
91 // NB: classes with call methods are subtypes of function 91 // NB: classes with call methods are subtypes of function
92 // types, but the function type is not assignable to the class 92 // types, but the function type is not assignable to the class
93 assert(toType.isSubtypeOf(fromType) || fromType.isAssignableTo(toType)); 93 assert(toType.isSubtypeOf(fromType) || fromType.isAssignableTo(toType));
94 94
95 // Handle null call specially. 95 // Handle null call specially.
96 if (expression is NullLiteral) { 96 if (expression is NullLiteral) {
97 // TODO(vsm): Create a NullCast for this once we revisit nonnullability. 97 // TODO(vsm): Create a NullCast for this once we revisit nonnullability.
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 super(expression); 539 super(expression);
540 540
541 @override 541 @override
542 List<Object> get arguments => [node, baseType, expectedType]; 542 List<Object> get arguments => [node, baseType, expectedType];
543 @override 543 @override
544 String get message => 'Type check failed: {0} ({1}) is not of type {2}'; 544 String get message => 'Type check failed: {0} ({1}) is not of type {2}';
545 545
546 @override 546 @override
547 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; 547 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR';
548 } 548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698