summaryrefslogtreecommitdiff
path: root/vala/valabinaryexpression.vala
diff options
context:
space:
mode:
authorwszqkzqk <wszqkzqk@qq.com>2022-12-13 21:56:53 +0800
committerRico Tzschichholz <ricotz@ubuntu.com>2022-12-22 17:13:52 +0100
commitc5679d09cdc8b49c9b886fc6617db901350c301d (patch)
treea75445dfdeaef656e8c03140f793028c3e746369 /vala/valabinaryexpression.vala
parenta67d19f51082944e3751760d6c0ae09efc35b860 (diff)
downloadvala-c5679d09cdc8b49c9b886fc6617db901350c301d.tar.gz
parser: Properly handle chained equality expressions
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1385
Diffstat (limited to 'vala/valabinaryexpression.vala')
-rw-r--r--vala/valabinaryexpression.vala44
1 files changed, 35 insertions, 9 deletions
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 6545e1cff..d627e2942 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -467,7 +467,12 @@ public class Vala.BinaryExpression : Expression {
DataType resulting_type;
if (is_chained) {
- var lbe = (BinaryExpression) left;
+ unowned BinaryExpression lbe = (BinaryExpression) left;
+ if (lbe.right.value_type.compatible (context.analyzer.string_type)
+ && right.value_type.compatible (context.analyzer.string_type)) {
+ value_type = context.analyzer.bool_type;
+ break;
+ }
resulting_type = context.analyzer.get_arithmetic_result_type (lbe.right.target_type, right.target_type);
} else {
resulting_type = context.analyzer.get_arithmetic_result_type (left.target_type, right.target_type);
@@ -475,7 +480,14 @@ public class Vala.BinaryExpression : Expression {
if (resulting_type == null) {
error = true;
- Report.error (source_reference, "Relational operation not supported for types `%s' and `%s'", left.value_type.to_string (), right.value_type.to_string ());
+ unowned DataType left_type;
+ if (is_chained) {
+ unowned BinaryExpression lbe = (BinaryExpression) left;
+ left_type = lbe.right.value_type;
+ } else {
+ left_type = left.value_type;
+ }
+ Report.error (source_reference, "Relational operation not supported for types `%s' and `%s'", left_type.to_string (), right.value_type.to_string ());
return false;
}
@@ -515,17 +527,31 @@ public class Vala.BinaryExpression : Expression {
}
}
- if (!right.value_type.compatible (left.value_type)
- && !left.value_type.compatible (right.value_type)) {
- Report.error (source_reference, "Equality operation: `%s' and `%s' are incompatible", right.value_type.to_string (), left.value_type.to_string ());
- error = true;
- return false;
+ DataType resulting_type;
+ if (is_chained) {
+ unowned BinaryExpression lbe = (BinaryExpression) left;
+ resulting_type = context.analyzer.get_arithmetic_result_type (lbe.right.target_type, right.target_type);
+ if (!right.value_type.compatible (lbe.right.value_type)
+ && !lbe.right.value_type.compatible (right.value_type)) {
+ Report.error (source_reference, "Equality operation: `%s' and `%s' are incompatible", right.value_type.to_string (), lbe.right.value_type.to_string ());
+ error = true;
+ return false;
+ }
+ } else {
+ resulting_type = context.analyzer.get_arithmetic_result_type (left.target_type, right.target_type);
+ if (!right.value_type.compatible (left.value_type)
+ && !left.value_type.compatible (right.value_type)) {
+ Report.error (source_reference, "Equality operation: `%s' and `%s' are incompatible", right.value_type.to_string (), left.value_type.to_string ());
+ error = true;
+ return false;
+ }
}
- var resulting_type = context.analyzer.get_arithmetic_result_type (left.target_type, right.target_type);
if (resulting_type != null) {
// numeric operation
- left.target_type = resulting_type.copy ();
+ if (!is_chained) {
+ left.target_type = resulting_type.copy ();
+ }
right.target_type = resulting_type.copy ();
}