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

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

Issue 1663533002: fixes #25640, errors on function downcasts when we know it's an exact type (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 if (expression is InstanceCreationExpression) { 132 if (expression is InstanceCreationExpression) {
133 ConstructorElement e = expression.staticElement; 133 ConstructorElement e = expression.staticElement;
134 if (e == null || !e.isFactory) { 134 if (e == null || !e.isFactory) {
135 // fromT should be an exact type - this will almost certainly fail at 135 // fromT should be an exact type - this will almost certainly fail at
136 // runtime. 136 // runtime.
137 return new StaticTypeError(rules, expression, toT, reason: reason); 137 return new StaticTypeError(rules, expression, toT, reason: reason);
138 } 138 }
139 } 139 }
140 140
141 Element staticElement = null;
142 if (expression is PropertyAccess) {
143 staticElement = expression.propertyName.staticElement;
144 } else if (expression is Identifier) {
145 staticElement = expression.staticElement;
146 }
147 // First class functions, where we know the original declaration, will have
148 // an exact type, so we know a downcast will fail.
149 if (staticElement is FunctionElement) {
vsm 2016/02/03 23:51:59 Does this guarantee a static or top-level function
Jennifer Messerly 2016/02/04 00:41:30 It includes top-level and local functions (named,
150 return new StaticTypeError(rules, expression, toT, reason: reason);
151 }
152
141 // TODO(vsm): Change this to an assert when we have generic methods and 153 // TODO(vsm): Change this to an assert when we have generic methods and
142 // fix TypeRules._coerceTo to disallow implicit sideways casts. 154 // fix TypeRules._coerceTo to disallow implicit sideways casts.
143 if (!rules.isSubtypeOf(toT, fromT)) { 155 if (!rules.isSubtypeOf(toT, fromT)) {
144 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); 156 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT));
145 return new DownCastComposite(rules, expression, cast); 157 return new DownCastComposite(rules, expression, cast);
146 } 158 }
147 159
148 // Composite cast: these are more likely to fail. 160 // Composite cast: these are more likely to fail.
149 if (!rules.isGroundType(toT)) { 161 if (!rules.isGroundType(toT)) {
150 // This cast is (probably) due to our different treatment of dynamic. 162 // This cast is (probably) due to our different treatment of dynamic.
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 @override 565 @override
554 List<Object> get arguments => [node, baseType, expectedType]; 566 List<Object> get arguments => [node, baseType, expectedType];
555 @override 567 @override
556 String get message => 568 String get message =>
557 'Type check failed: {0} ({1}) is not of type {2}' + 569 'Type check failed: {0} ({1}) is not of type {2}' +
558 ((reason == null) ? '' : ' because $reason'); 570 ((reason == null) ? '' : ' because $reason');
559 571
560 @override 572 @override
561 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR'; 573 String get name => 'STRONG_MODE_STATIC_TYPE_ERROR';
562 } 574 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698