[vala] Fix coalescing operator semantics check.
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix coalescing operator semantics check.
- Date: Sat, 11 Jan 2014 11:17:24 +0000 (UTC)
commit 58259ec0ef06548786a0d650c568267f5a6f0f17
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Jan 11 12:13:38 2014 +0100
Fix coalescing operator semantics check.
The left operand was not put in any code block
before the check, thus it wasn't able to transform itself.
Fixes bug 691514.
tests/Makefile.am | 1 +
tests/control-flow/bug691514.vala | 23 +++++++++++++++++++++++
vala/valabinaryexpression.vala | 6 +++++-
3 files changed, 29 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6a36a4d..141b048 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -65,6 +65,7 @@ TESTS = \
control-flow/sideeffects.vala \
control-flow/bug652549.vala \
control-flow/bug665904.vala \
+ control-flow/bug691514.vala \
enums/enums.vala \
enums/bug673879.vala \
structs/structs.vala \
diff --git a/tests/control-flow/bug691514.vala b/tests/control-flow/bug691514.vala
new file mode 100644
index 0000000..661e73c
--- /dev/null
+++ b/tests/control-flow/bug691514.vala
@@ -0,0 +1,23 @@
+public string[] test() throws Error {
+ return { null, "1" };
+}
+
+void main() {
+ string t = (true ? "1" : "2") ?? "3";
+ assert (t == "1");
+
+ t = (false ? "1" : "2") ?? "3";
+ assert (t == "2");
+
+ t = (true ? null : "2") ?? "3";
+ assert (t == "3");
+
+ t = (false ? "1" : null) ?? "3";
+ assert (t == "3");
+
+ t = test()[0] ?? "2";
+ assert (t == "2");
+
+ t = test()[1] ?? "2";
+ assert (t == "1");
+}
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 22c4483..2b7289c 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -196,7 +196,6 @@ public class Vala.BinaryExpression : Expression {
if (operator == BinaryOperator.COALESCE) {
var local = new LocalVariable (null, get_temp_name (), left, source_reference);
var decl = new DeclarationStatement (local, source_reference);
- decl.check (context);
var right_stmt = new ExpressionStatement (new Assignment (new MemberAccess.simple
(local.name, right.source_reference), right, AssignmentOperator.SIMPLE, right.source_reference),
right.source_reference);
@@ -211,6 +210,11 @@ public class Vala.BinaryExpression : Expression {
insert_statement (context.analyzer.insert_block, decl);
insert_statement (context.analyzer.insert_block, if_stmt);
+ if (!decl.check (context)) {
+ error = true;
+ return false;
+ }
+
if (!if_stmt.check (context)) {
error = true;
return false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]