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

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

Issue 1578863004: fixes #24711, allow factory constructors to be downcast (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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/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 /// 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // fromT should be an exact type - this will almost certainly fail at 126 // fromT should be an exact type - this will almost certainly fail at
127 // runtime. 127 // runtime.
128 return new StaticTypeError(rules, expression, toT, reason: reason); 128 return new StaticTypeError(rules, expression, toT, reason: reason);
129 } 129 }
130 if (expression is FunctionExpression) { 130 if (expression is FunctionExpression) {
131 // fromT should be an exact type - this will almost certainly fail at 131 // fromT should be an exact type - this will almost certainly fail at
132 // runtime. 132 // runtime.
133 return new UninferredClosure(rules, expression, cast); 133 return new UninferredClosure(rules, expression, cast);
134 } 134 }
135 if (expression is InstanceCreationExpression) { 135 if (expression is InstanceCreationExpression) {
136 // fromT should be an exact type - this will almost certainly fail at 136 ConstructorElement e = expression.staticElement;
137 // runtime. 137 if (e == null || !e.isFactory) {
138 return new StaticTypeError(rules, expression, toT, reason: reason); 138 // fromT should be an exact type - this will almost certainly fail at
139 // runtime.
140 return new StaticTypeError(rules, expression, toT, reason: reason);
141 }
139 } 142 }
140 143
141 // TODO(vsm): Change this to an assert when we have generic methods and 144 // TODO(vsm): Change this to an assert when we have generic methods and
142 // fix TypeRules._coerceTo to disallow implicit sideways casts. 145 // fix TypeRules._coerceTo to disallow implicit sideways casts.
143 if (!rules.isSubtypeOf(toT, fromT)) { 146 if (!rules.isSubtypeOf(toT, fromT)) {
144 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT)); 147 assert(toT.isSubtypeOf(fromT) || fromT.isAssignableTo(toT));
145 return new DownCastComposite(rules, expression, cast); 148 return new DownCastComposite(rules, expression, cast);
146 } 149 }
147 150
148 // Composite cast: these are more likely to fail. 151 // Composite cast: these are more likely to fail.
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // TODO(vsm,leafp): Remove this. 565 // TODO(vsm,leafp): Remove this.
563 class UninferredClosure extends DownCast { 566 class UninferredClosure extends DownCast {
564 UninferredClosure(TypeSystem rules, FunctionExpression expression, Cast cast) 567 UninferredClosure(TypeSystem rules, FunctionExpression expression, Cast cast)
565 : super._internal(rules, expression, cast); 568 : super._internal(rules, expression, cast);
566 569
567 @override 570 @override
568 String get name => 'STRONG_MODE_UNINFERRED_CLOSURE'; 571 String get name => 'STRONG_MODE_UNINFERRED_CLOSURE';
569 572
570 toErrorCode() => new StaticTypeWarningCode(name, message); 573 toErrorCode() => new StaticTypeWarningCode(name, message);
571 } 574 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698