Add support for &&, || and ?? operators

Change-Id: Ibb6269b349b3d0ffcf1068442c70ef46a6f521eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106948
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2019-06-21 14:16:57 +00:00 committed by commit-bot@chromium.org
parent 77668f4e58
commit 735eb21529
2 changed files with 32 additions and 0 deletions

View file

@ -214,6 +214,12 @@ class GraphBuilder extends GeneralizingAstVisitor<DecoratedType> {
: conditionInfo.not(node);
}
return _nonNullableBoolType;
} else if (operatorType == TokenType.AMPERSAND_AMPERSAND ||
operatorType == TokenType.BAR_BAR ||
operatorType == TokenType.QUESTION_QUESTION) {
_handleAssignment(_notNullType, node.leftOperand);
node.rightOperand.accept(this);
return _nonNullableBoolType;
} else if (operatorType.isUserDefinableOperator) {
_handleAssignment(_notNullType, node.leftOperand);
var callee = node.staticElement;
@ -228,6 +234,8 @@ class GraphBuilder extends GeneralizingAstVisitor<DecoratedType> {
return calleeType.returnType;
} else {
// TODO(paulberry)
node.leftOperand.accept(this);
node.rightOperand.accept(this);
_unimplemented(
node, 'Binary expression with operator ${node.operator.lexeme}');
}

View file

@ -294,6 +294,14 @@ int f(int i, int j) => i & j;
assertNoUpstreamNullability(decoratedTypeAnnotation('int f').node);
}
test_binaryExpression_ampersandAmpersand() async {
await analyze('''
bool f(bool i, bool j) => i && j;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('bool i').node);
}
test_binaryExpression_bar_result_not_null() async {
await analyze('''
int f(int i, int j) => i | j;
@ -302,6 +310,14 @@ int f(int i, int j) => i | j;
assertNoUpstreamNullability(decoratedTypeAnnotation('int f').node);
}
test_binaryExpression_barBar() async {
await analyze('''
bool f(bool i, bool j) => i || j;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('bool i').node);
}
test_binaryExpression_caret_result_not_null() async {
await analyze('''
int f(int i, int j) => i ^ j;
@ -458,6 +474,14 @@ Int f(Int i, Int j) => i + j/*check*/;
hard: true));
}
test_binaryExpression_questionQuestion() async {
await analyze('''
int f(int i, int j) => i ?? j;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('int i').node);
}
test_binaryExpression_slash_result_not_null() async {
await analyze('''
double f(int i, int j) => i / j;