diff options
author | Luca Bruno <lucabru@src.gnome.org> | 2014-01-11 12:13:38 +0100 |
---|---|---|
committer | Luca Bruno <lucabru@src.gnome.org> | 2014-01-11 12:17:06 +0100 |
commit | 58259ec0ef06548786a0d650c568267f5a6f0f17 (patch) | |
tree | 7768b5d54c4ad38ccdf68eafc5b3c6211fd6c29d | |
parent | 86bf398bdff96c03ffb34ef0a60d311557db5077 (diff) | |
download | vala-58259ec0ef06548786a0d650c568267f5a6f0f17.tar.gz |
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.
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/control-flow/bug691514.vala | 23 | ||||
-rw-r--r-- | vala/valabinaryexpression.vala | 6 |
3 files changed, 29 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 6a36a4dd3..141b0484b 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 000000000..661e73c04 --- /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 22c448384..2b7289c05 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; |