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

Unified Diff: pkg/analyzer/lib/src/dart/ast/utilities.dart

Issue 2586363004: Support + concatenation in constant expressions with strings (Closed)
Patch Set: More tests for constant string concatenation error states Created 4 years 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 | pkg/analyzer/test/src/dart/ast/utilities_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/ast/utilities.dart
diff --git a/pkg/analyzer/lib/src/dart/ast/utilities.dart b/pkg/analyzer/lib/src/dart/ast/utilities.dart
index 3efd68b24894e652a1fd46e77a69644023dec045..8ac2c16df693767f4f30d52b213241b5ed254bae 100644
--- a/pkg/analyzer/lib/src/dart/ast/utilities.dart
+++ b/pkg/analyzer/lib/src/dart/ast/utilities.dart
@@ -2190,16 +2190,21 @@ class AstComparator implements AstVisitor<bool> {
* > expressions that evaluate to an integer value or to <b>null</b>.
* > </span>
* > * <span>
- * > An expression of one of the forms <i>-e</i>, <i>e<sub>1</sub> +
- * > e<sub>2</sub></i>, <i>e<sub>1</sub> -e<sub>2</sub></i>,
- * > <i>e<sub>1</sub> * e<sub>2</sub></i>, <i>e<sub>1</sub> /
- * > e<sub>2</sub></i>, <i>e<sub>1</sub> ~/ e<sub>2</sub></i>,
- * > <i>e<sub>1</sub> &gt; e<sub>2</sub></i>, <i>e<sub>1</sub> &lt;
- * > e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;= e<sub>2</sub></i>,
- * > <i>e<sub>1</sub> &lt;= e<sub>2</sub></i> or <i>e<sub>1</sub> %
- * > e<sub>2</sub></i>, where <i>e</i>, <i>e<sub>1</sub></i> and
- * > <i>e<sub>2</sub></i> are constant expressions that evaluate to a numeric
- * > value or to <b>null</b>.
+ * > An expression of one of the forms <i>-e</i>, <i>e<sub>1</sub>
+ * > -e<sub>2</sub></i>, <i>e<sub>1</sub> * e<sub>2</sub></i>,
+ * > <i>e<sub>1</sub> / e<sub>2</sub></i>, <i>e<sub>1</sub> ~/
+ * > e<sub>2</sub></i>, <i>e<sub>1</sub> &gt; e<sub>2</sub></i>,
+ * > <i>e<sub>1</sub> &lt; e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;=
+ * > e<sub>2</sub></i>, <i>e<sub>1</sub> &lt;= e<sub>2</sub></i> or
+ * > <i>e<sub>1</sub> % e<sub>2</sub></i>, where <i>e</i>,
+ * > <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant expressions
+ * > that evaluate to a numeric value or to <b>null</b>.
+ * > </span>
+ * > * <span>
+ * > An expression of one the form <i>e<sub>1</sub> + e<sub>2</sub></i>,
+ * > <i>e<sub>1</sub> -e<sub>2</sub></i> where <i>e<sub>1</sub> and
+ * > e<sub>2</sub></i> are constant expressions that evaluate to a numeric or
+ * > string value or to <b>null</b>.
* > </span>
* > * <span>
* > An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> :
@@ -2208,6 +2213,8 @@ class AstComparator implements AstVisitor<bool> {
* > evaluates to a boolean value.
* > </span>
*
+ * However, this comment is now at least a little bit out of sync with the spec.
+ *
* The values returned by instances of this class are therefore `null` and
* instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and
* `DartObject`.
@@ -2332,7 +2339,8 @@ class ConstantEvaluator extends GeneralizingAstVisitor<Object> {
}
} else if (node.operator.type == TokenType.PLUS) {
// numeric or {@code null}
- if (leftOperand is num && rightOperand is num) {
+ if ((leftOperand is num && rightOperand is num) ||
+ (leftOperand is String && rightOperand is String)) {
return leftOperand + rightOperand;
}
} else if (node.operator.type == TokenType.STAR) {
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/ast/utilities_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698