]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix semantics for coalesce operator when target_type is null.
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 26 Jan 2014 11:10:57 +0000 (12:10 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Sun, 26 Jan 2014 11:12:20 +0000 (12:12 +0100)
Fixes bug 639482

tests/Makefile.am
tests/control-flow/bug639482.vala [new file with mode: 0644]
vala/valabinaryexpression.vala

index 85a92139b10791a02f5b9695ea998b35392f98d8..5d89abfe7566e8ddba3ec8ea40053e515e9d1176 100644 (file)
@@ -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 (file)
index 0000000..27a8e20
--- /dev/null
@@ -0,0 +1,4 @@
+void main () {
+       string empty = null;
+       assert ((false ? "A" : (empty ?? "B")) == "B");
+}
index 2b7289c0573172f8022ca98264844d719d91af8d..19766e12ff85327ca2a33b05a718f495df49a087 100644 (file)
@@ -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;
                }