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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java

Issue 9875002: Remove error message when compile time constants used in +,-,/,* expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added test mixing int and doubles 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 | compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java b/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
index a57418f8dd9d9d0f54af561be7fbe69badd37f8c..bfe7a3b95ae7afc7fc1489e938762c231e17f13f 100644
--- a/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
@@ -215,19 +215,22 @@ public class CompileTimeConstantAnalyzer {
case ADD:
if (lhsType.equals(stringType)) {
+ // TODO(zundel): remove this when + no longer acceptable as string concat operator
if (checkString(rhs, rhsType)) {
rememberInferredType(x, stringType);
}
- } else if (checkNumber(lhs, lhsType) && checkNumber(rhs, rhsType)) {
- rememberInferredType(x, numType);
+ } else {
+ checkMathExpression(x, lhs, rhs, lhsType, rhsType);
}
break;
case SUB:
case MUL:
case DIV:
+ checkMathExpression(x, lhs, rhs, lhsType, rhsType);
+ break;
case MOD:
if (checkNumber(lhs, lhsType) && checkNumber(rhs, rhsType)) {
- rememberInferredType(x, numType);
+ rememberInferredType(x, intType);
}
break;
case LT:
@@ -246,6 +249,23 @@ public class CompileTimeConstantAnalyzer {
return null;
}
+ private void checkMathExpression(DartBinaryExpression x,
+ DartExpression lhs, DartExpression rhs,
+ Type lhsType, Type rhsType) {
+ if (checkNumber(lhs, lhsType) && checkNumber(rhs, rhsType)) {
+ if (lhsType.equals(intType) && rhsType.equals(intType)) {
+ rememberInferredType(x, intType);
+ } else if (lhsType.equals(doubleType) && rhsType.equals(doubleType)) {
+ rememberInferredType(x, doubleType);
+ } else if (lhsType.equals(doubleType) && rhsType.equals(intType)
+ || lhsType.equals(intType) && rhsType.equals(doubleType)) {
+ rememberInferredType(x, doubleType);
+ } else {
+ rememberInferredType(x, numType);
+ }
+ }
+ }
+
@Override
public Void visitBooleanLiteral(DartBooleanLiteral x) {
rememberInferredType(x, boolType);
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698