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

Side by Side Diff: frog/leg/operations.dart

Issue 9866027: Error out on compile-time constants if equality is tested on bad types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 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 | Annotate | Revision Log
« no previous file with comments | « frog/leg/compile_time_constants.dart ('k') | tests/co19/co19-leg.status » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 interface Operation { 5 interface Operation {
6 6
7 } 7 }
8 8
9 interface UnaryOperation extends Operation { 9 interface UnaryOperation extends Operation {
10 /** Returns [:null:] if it was unable to fold the operation. */ 10 /** Returns [:null:] if it was unable to fold the operation. */
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 class EqualsOperation implements BinaryOperation { 260 class EqualsOperation implements BinaryOperation {
261 const EqualsOperation(); 261 const EqualsOperation();
262 Constant fold(Constant left, Constant right) { 262 Constant fold(Constant left, Constant right) {
263 if (left.isNum() && right.isNum()) { 263 if (left.isNum() && right.isNum()) {
264 // Numbers need to be treated specially because: NaN != NaN, -0.0 == 0.0, 264 // Numbers need to be treated specially because: NaN != NaN, -0.0 == 0.0,
265 // and 1 == 1.0. 265 // and 1 == 1.0.
266 NumConstant leftNum = left; 266 NumConstant leftNum = left;
267 NumConstant rightNum = right; 267 NumConstant rightNum = right;
268 return new BoolConstant(leftNum.value == rightNum.value); 268 return new BoolConstant(leftNum.value == rightNum.value);
269 } 269 }
270 if (left.isConstructedObject()) {
271 // Unless we know that the user-defined object does not implement the
272 // equality operator we cannot fold here.
273 return null;
274 }
270 return new BoolConstant(left == right); 275 return new BoolConstant(left == right);
271 } 276 }
272 } 277 }
273 278
274 class IdentityOperation implements BinaryOperation { 279 class IdentityOperation implements BinaryOperation {
275 const IdentityOperation(); 280 const IdentityOperation();
276 Constant fold(Constant left, Constant right) { 281 Constant fold(Constant left, Constant right) {
277 return new BoolConstant(left == right); 282 return new BoolConstant(left == right);
278 } 283 }
279 } 284 }
OLDNEW
« no previous file with comments | « frog/leg/compile_time_constants.dart ('k') | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698