diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-03-25 12:46:15 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-03-25 13:57:13 +0100 |
commit | 7d771a0c07d63cb7605cbdc28dd8df50719731f8 (patch) | |
tree | ace6b2288faa24b4fcc7b4596acb93ede097692c /vala/valabinaryexpression.vala | |
parent | 2d9c89eff5bcded0ae9c9807a33d10b97b18aaaa (diff) | |
download | vala-7d771a0c07d63cb7605cbdc28dd8df50719731f8.tar.gz |
codegen: Move implicit GValue cast for comparison to BinaryExpression
Handle "==" and "!=" only as it was done before.
This generates correct c-code for boxed simple-types and will perform
value-based comparisons.
See https://bugzilla.gnome.org/show_bug.cgi?id=585063
Diffstat (limited to 'vala/valabinaryexpression.vala')
-rw-r--r-- | vala/valabinaryexpression.vala | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala index 0dd61b6c1..eb1ea1b8c 100644 --- a/vala/valabinaryexpression.vala +++ b/vala/valabinaryexpression.vala @@ -442,6 +442,26 @@ public class Vala.BinaryExpression : Expression { || operator == BinaryOperator.INEQUALITY) { /* relational operation */ + // Implicit cast for comparsion expression of GValue with other type + var gvalue_type = context.analyzer.gvalue_type.data_type; + if ((left.target_type.data_type == gvalue_type && right.target_type.data_type != gvalue_type) + || (left.target_type.data_type != gvalue_type && right.target_type.data_type == gvalue_type)) { + Expression gvalue_expr; + DataType target_type; + if (left.target_type.data_type == gvalue_type) { + gvalue_expr = left; + target_type = right.target_type; + } else { + gvalue_expr = right; + target_type = left.target_type; + } + + var cast_expr = new CastExpression (gvalue_expr, target_type, gvalue_expr.source_reference); + replace_expression (gvalue_expr, cast_expr); + checked = false; + return check (context); + } + 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".printf (right.value_type.to_string (), left.value_type.to_string ())); |