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

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

Issue 1577293002: Implement (partially) ?? being compile-time constant in analyzer. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comment Created 4 years, 11 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 | tests/language/language_analyzer2.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a56197896785725423da2add3721501023f16a5c..ce6ed09477528f9feb0257ddebcb9a17a5f13394 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -1616,7 +1616,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);
@@ -1665,6 +1667,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);
@@ -2307,6 +2312,17 @@ 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) {
« no previous file with comments | « no previous file | tests/language/language_analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698