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

Unified Diff: lib/src/compiler/code_generator.dart

Issue 2042883004: Handle more boolean conversion cases. (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 6 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 | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index be0dc06fd553c9d925704116ea161195f880a5ff..4c8001751fb93d265197105016866d1a2c5c5d3b 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -3468,6 +3468,14 @@ class CodeGenerator extends GeneralizingAstVisitor
@override
JS.Expression visitBinaryExpression(BinaryExpression node) {
var op = node.operator;
+
+ // The operands of logical boolean operators are subject to boolean
+ // conversion.
+ if (op.type == TokenType.BAR_BAR ||
+ op.type == TokenType.AMPERSAND_AMPERSAND) {
+ return _visitTest(node);
Jennifer Messerly 2016/06/07 19:28:35 Reading this, I was confused ... my thought was "s
+ }
+
var left = node.leftOperand;
var right = node.rightOperand;
@@ -3923,6 +3931,11 @@ class CodeGenerator extends GeneralizingAstVisitor
@override
JS.Expression visitPrefixExpression(PrefixExpression node) {
var op = node.operator;
+
+ // Logical negation, `!e`, is a boolean conversion context since it is
+ // defined as `e ? false : true`.
+ if (op.lexeme == '!') return _visitTest(node);
+
var expr = node.operand;
var dispatchType = getStaticType(expr);
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698