[vala] Fix semantics for coalesce operator when target_type is null.
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix semantics for coalesce operator when target_type is null.
- Date: Sun, 26 Jan 2014 11:12:54 +0000 (UTC)
commit 6949360735ce69776f3e64d25fc3efab5ce387e5
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Jan 26 12:10:57 2014 +0100
Fix semantics for coalesce operator when target_type is null.
Fixes bug 639482
tests/Makefile.am | 1 +
tests/control-flow/bug639482.vala | 4 ++++
vala/valabinaryexpression.vala | 14 +++++++++++---
3 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 85a9213..5d89abf 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 0000000..27a8e20
--- /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 2b7289c..19766e1 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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]