From: Luca Bruno Date: Sun, 26 Jan 2014 11:10:57 +0000 (+0100) Subject: Fix semantics for coalesce operator when target_type is null. X-Git-Tag: 0.23.2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6949360735ce69776f3e64d25fc3efab5ce387e5;p=thirdparty%2Fvala.git Fix semantics for coalesce operator when target_type is null. Fixes bug 639482 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 85a92139b..5d89abfe7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -63,6 +63,7 @@ TESTS = \ control-flow/foreach.vala \ control-flow/switch.vala \ control-flow/sideeffects.vala \ + control-flow/bug639482.vala \ control-flow/bug652549.vala \ control-flow/bug665904.vala \ control-flow/bug691514.vala \ diff --git a/tests/control-flow/bug639482.vala b/tests/control-flow/bug639482.vala new file mode 100644 index 000000000..27a8e20ba --- /dev/null +++ b/tests/control-flow/bug639482.vala @@ -0,0 +1,4 @@ +void main () { + string empty = null; + assert ((false ? "A" : (empty ?? "B")) == "B"); +} diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala index 2b7289c05..19766e12f 100644 --- a/vala/valabinaryexpression.vala +++ b/vala/valabinaryexpression.vala @@ -221,10 +221,18 @@ public class Vala.BinaryExpression : Expression { } var ma = new MemberAccess.simple (local.name, source_reference); - ma.target_type = target_type; - ma.check (context); + Expression replace = ma; - parent_node.replace_expression (this, ma); + if (target_type == null) { + replace = new ReferenceTransferExpression (replace, source_reference); + replace.target_type = local.variable_type.copy (); + replace.target_type.value_owned = true; + } else { + replace.target_type = target_type.copy (); + } + replace.check (context); + + parent_node.replace_expression (this, replace); return true; }