]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix coalescing operator semantics check.
authorLuca Bruno <lucabru@src.gnome.org>
Sat, 11 Jan 2014 11:13:38 +0000 (12:13 +0100)
committerLuca Bruno <lucabru@src.gnome.org>
Sat, 11 Jan 2014 11:17:06 +0000 (12:17 +0100)
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
tests/control-flow/bug691514.vala [new file with mode: 0644]
vala/valabinaryexpression.vala

index 6a36a4dd39c051789df7b96e3e1b9df4ce87b4e8..141b0484bcb6ea9ab0d3cb4969013a72f3fd0861 100644 (file)
@@ -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 (file)
index 0000000..661e73c
--- /dev/null
@@ -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");
+}
index 22c4483842727bb134a23ea1aa4aacf21d65f9a0..2b7289c0573172f8022ca98264844d719d91af8d 100644 (file)
@@ -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;