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

Unified Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 1493693002: Make ?? a compile-time constant operator. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix test, runs in dart2js and analyzer. Created 5 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
Index: pkg/analyzer/lib/src/generated/constant.dart
diff --git a/pkg/analyzer/lib/src/generated/constant.dart b/pkg/analyzer/lib/src/generated/constant.dart
index 24125064171085e4cfad5f3679f3da5839bd62cb..c4d7027ded91d9fa85af5c4a28d96f224fce8710 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -1533,7 +1533,9 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
DartObjectImpl rightResult = node.rightOperand.accept(this);
TokenType operatorType = node.operator.type;
// 'null' is almost never good operand
- if (operatorType != TokenType.BANG_EQ && operatorType != TokenType.EQ_EQ) {
+ if (operatorType != TokenType.BANG_EQ &&
+ operatorType != TokenType.EQ_EQ &&
+ operatorType != TokenType.QUESTION_QUESTION) {
if (leftResult != null && leftResult.isNull ||
rightResult != null && rightResult.isNull) {
_error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
@@ -1582,6 +1584,9 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
return _dartObjectComputer.divide(node, leftResult, rightResult);
} else if (operatorType == TokenType.TILDE_SLASH) {
return _dartObjectComputer.integerDivide(node, leftResult, rightResult);
+ } else if (operatorType == TokenType.QUESTION_QUESTION) {
+ return _dartObjectComputer.questionQuestion(
+ node, leftResult, rightResult);
} else {
// TODO(brianwilkerson) Figure out which error to report.
_error(node, null);
@@ -2295,6 +2300,15 @@ class DartObjectComputer {
return null;
}
+ DartObjectImpl questionQuestion(Expression node, DartObjectImpl leftOperand,
+ DartObjectImpl rightOperand) {
+ if (leftOperand != null && rightOperand != null) {
+ if (leftOperand.isNull) return rightOperand;
+ return leftOperand;
+ }
+ return null;
+ }
+
DartObjectImpl greaterThan(BinaryExpression node, DartObjectImpl leftOperand,
DartObjectImpl rightOperand) {
if (leftOperand != null && rightOperand != null) {

Powered by Google App Engine
This is Rietveld 408576698