Skip to content

Commit

Permalink
vala: Don't falsely resolve binary-expression to bool
Browse files Browse the repository at this point in the history
  • Loading branch information
ricotz committed Oct 28, 2019
1 parent 3760d61 commit f7b6119
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/Makefile.am
Expand Up @@ -200,6 +200,8 @@ TESTS = \
control-semantic/argument-owned-ref.test \
control-semantic/argument-value-out.test \
control-semantic/argument-value-ref.test \
control-semantic/condition-not-boolean.test \
control-semantic/expression-not-boolean.test \
control-semantic/literal-immutable.test \
control-semantic/member-incompatible-type.test \
control-semantic/member-invalid.test \
Expand Down
7 changes: 7 additions & 0 deletions tests/control-semantic/condition-not-boolean.test
@@ -0,0 +1,7 @@
Invalid Code

void main () {
if (true != false & 0) {
assert_not_reached ();
}
}
5 changes: 5 additions & 0 deletions tests/control-semantic/expression-not-boolean.test
@@ -0,0 +1,5 @@
Invalid Code

void main () {
bool foo = true != false & 0;
}
8 changes: 7 additions & 1 deletion vala/valabinaryexpression.vala
Expand Up @@ -498,7 +498,13 @@ public class Vala.BinaryExpression : Expression {
left.target_type.nullable = false;
right.target_type.nullable = false;

value_type = left.target_type.copy ();
// Don't falsely resolve to bool
if (left.value_type.compatible (context.analyzer.bool_type)
&& !right.value_type.compatible (context.analyzer.bool_type)) {
value_type = right.target_type.copy ();
} else {
value_type = left.target_type.copy ();
}
} else if (operator == BinaryOperator.AND
|| operator == BinaryOperator.OR) {
if (!left.value_type.compatible (context.analyzer.bool_type) || !right.value_type.compatible (context.analyzer.bool_type)) {
Expand Down

0 comments on commit f7b6119

Please sign in to comment.