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

Unified Diff: frog/leg/compile_time_constants.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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | frog/leg/operations.dart » ('j') | frog/leg/operations.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
« no previous file with comments | « no previous file | frog/leg/operations.dart » ('j') | frog/leg/operations.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698