From: Luca Bruno Date: Sun, 26 Jan 2014 17:06:43 +0000 (+0100) Subject: Fix regression when coalescing: value owned if either of the two is owned X-Git-Tag: 0.23.2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=517d25a5daf7016b6af85173af184eb7e6b5e9c4;p=thirdparty%2Fvala.git Fix regression when coalescing: value owned if either of the two is owned --- diff --git a/tests/control-flow/bug639482.vala b/tests/control-flow/bug639482.vala index 27a8e20ba..4a0a5508b 100644 --- a/tests/control-flow/bug639482.vala +++ b/tests/control-flow/bug639482.vala @@ -1,4 +1,14 @@ +public string test() throws Error { + return "foo"; +} + void main () { string empty = null; assert ((false ? "A" : (empty ?? "B")) == "B"); + + string foo = "bar" ?? test (); + assert (foo == "bar"); + + foo = empty ?? test (); + assert (foo == "foo"); } diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala index 9c1ef4c98..bdd9e5eb2 100644 --- a/vala/valabinaryexpression.vala +++ b/vala/valabinaryexpression.vala @@ -198,8 +198,24 @@ public class Vala.BinaryExpression : Expression { error = true; return false; } - - var local = new LocalVariable (left.value_type != null ? left.value_type.copy () : null, get_temp_name (), left, source_reference); + + if (!right.check (context)) { + error = true; + return false; + } + + DataType local_type = null; + if (left.value_type != null) { + local_type = left.value_type.copy (); + if (right.value_type != null && right.value_type.value_owned) { + // value owned if either left or right is owned + local_type.value_owned = true; + } + } else if (right.value_type != null) { + local_type = right.value_type.copy (); + } + + var local = new LocalVariable (local_type, get_temp_name (), left, source_reference); var decl = new DeclarationStatement (local, source_reference); var right_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple (local.name, right.source_reference), right, AssignmentOperator.SIMPLE, right.source_reference), right.source_reference);