Chromium Code Reviews| Index: frog/leg/compile_time_constants.dart |
| diff --git a/frog/leg/compile_time_constants.dart b/frog/leg/compile_time_constants.dart |
| index 7fdfbbe43a1d29006a9f103e5b20e8b30f79f90e..ba64d75ea765f507f8d9d519116017b9d3f6bc90 100644 |
| --- a/frog/leg/compile_time_constants.dart |
| +++ b/frog/leg/compile_time_constants.dart |
| @@ -16,6 +16,8 @@ class Constant implements Hashable { |
| bool isList() => false; |
| bool isMap() => false; |
| bool isConstructedObject() => false; |
| + /** Returns true if the constant is null, a bool, a number or a string. */ |
| + bool isPrimitive() => false; |
| /** Returns true if the constant is a list, a map or a constructed object. */ |
| bool isObject() => false; |
| @@ -26,6 +28,7 @@ class Constant implements Hashable { |
| class PrimitiveConstant extends Constant { |
| abstract get value(); |
| const PrimitiveConstant(); |
| + bool isPrimitive() => true; |
| bool operator ==(var other) { |
| if (other is !PrimitiveConstant) return false; |
| @@ -897,26 +900,34 @@ class CompileTimeConstantEvaluator extends AbstractVisitor { |
| folded = const GreaterEqualOperation().fold(left, right); |
| break; |
| case "==": |
| - folded = const EqualsOperation().fold(left, right); |
| + if (left.isPrimitive() && right.isPrimitive()) { |
|
Lasse Reichstein Nielsen
2012/03/27 08:12:12
Is "null" a numeric, string or boolean value? It s
floitsch
2012/03/28 00:25:21
Filed already a bug, and Gilad confirmed that null
|
| + folded = const EqualsOperation().fold(left, right); |
| + } |
| break; |
| case "===": |
| - folded = const IdentityOperation().fold(left, right); |
| + if (left.isPrimitive() && right.isPrimitive()) { |
| + folded = const IdentityOperation().fold(left, right); |
| + } |
| break; |
| case "!=": |
| - BoolConstant areEquals = const EqualsOperation().fold(left, right); |
| - if (areEquals === null) { |
| - folded = null; |
| - } else { |
| - folded = areEquals.negate(); |
| + if (left.isPrimitive() && right.isPrimitive()) { |
| + BoolConstant areEquals = const EqualsOperation().fold(left, right); |
| + if (areEquals === null) { |
| + folded = null; |
| + } else { |
| + folded = areEquals.negate(); |
| + } |
| } |
| break; |
| case "!==": |
| - BoolConstant areIdentical = |
| - const IdentityOperation().fold(left, right); |
| - if (areIdentical === null) { |
| - folded = null; |
| - } else { |
| - folded = areIdentical.negate(); |
| + if (left.isPrimitive() && right.isPrimitive()) { |
| + BoolConstant areIdentical = |
| + const IdentityOperation().fold(left, right); |
| + if (areIdentical === null) { |
|
Lasse Reichstein Nielsen
2012/03/27 08:12:12
Have you considered having a dedicated FoldingFail
floitsch
2012/03/28 00:25:21
I have considered it, but the problem is, that you
|
| + folded = null; |
| + } else { |
| + folded = areIdentical.negate(); |
| + } |
| } |
| break; |
| default: |