[vala] Fix regression when coalescing: value owned if either of the two is owned
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix regression when coalescing: value owned if either of the two is owned
- Date: Sun, 26 Jan 2014 17:07:23 +0000 (UTC)
commit 517d25a5daf7016b6af85173af184eb7e6b5e9c4
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Jan 26 18:06:43 2014 +0100
Fix regression when coalescing: value owned if either of the two is owned
tests/control-flow/bug639482.vala | 10 ++++++++++
vala/valabinaryexpression.vala | 20 ++++++++++++++++++--
2 files changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/tests/control-flow/bug639482.vala b/tests/control-flow/bug639482.vala
index 27a8e20..4a0a550 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 9c1ef4c..bdd9e5e 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]