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

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: Created 8 years, 8 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
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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 class EqualsOperation implements BinaryOperation { 235 class EqualsOperation implements BinaryOperation {
236 const EqualsOperation(); 236 const EqualsOperation();
237 Constant fold(Constant left, Constant right) { 237 Constant fold(Constant left, Constant right) {
238 if (left.isNum() && right.isNum()) { 238 if (left.isNum() && right.isNum()) {
239 // Numbers need to be treated specially because: NaN != NaN, -0.0 == 0.0, 239 // Numbers need to be treated specially because: NaN != NaN, -0.0 == 0.0,
240 // and 1 == 1.0. 240 // and 1 == 1.0.
241 NumConstant leftNum = left; 241 NumConstant leftNum = left;
242 NumConstant rightNum = right; 242 NumConstant rightNum = right;
243 return new BoolConstant(leftNum.value == rightNum.value); 243 return new BoolConstant(leftNum.value == rightNum.value);
244 } else if (!left.isConstructedObject()) {
Lasse Reichstein Nielsen 2012/03/27 08:12:12 I'd prefer else if (left.isConstructedObject())
floitsch 2012/03/28 00:25:21 hehe. that's what I had before. After long hesitat
245 // Unless we know that the user-defined object does not implement the
246 // equality operator we cannot fold here.
247 return new BoolConstant(left == right);
244 } 248 }
245 return new BoolConstant(left == right); 249 return null;
246 } 250 }
247 } 251 }
248 252
249 class IdentityOperation implements BinaryOperation { 253 class IdentityOperation implements BinaryOperation {
250 const IdentityOperation(); 254 const IdentityOperation();
251 Constant fold(Constant left, Constant right) { 255 Constant fold(Constant left, Constant right) {
252 return new BoolConstant(left == right); 256 return new BoolConstant(left == right);
253 } 257 }
254 } 258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698