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

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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | frog/leg/operations.dart » ('j') | no next file with comments »
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 c481947dbd3fa7ca2d593d8a0d751e88d3948005..94c98c5f9b08edbfd6af8cfd32eb8b6b882bee4e 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;
@@ -32,6 +34,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;
@@ -877,26 +880,34 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
folded = const GreaterEqualOperation().fold(left, right);
break;
case "==":
- folded = const EqualsOperation().fold(left, right);
+ if (left.isPrimitive() && right.isPrimitive()) {
+ 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) {
+ folded = null;
+ } else {
+ folded = areIdentical.negate();
+ }
}
break;
default:
« no previous file with comments | « no previous file | frog/leg/operations.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698