[vala] Set correct parent_statement for MemberInitializer



commit fb7687a16cf78c9ecf19720a3c70271dfaf98967
Author: Simon Werbeck <simon werbeck gmail com>
Date:   Fri Sep 28 16:13:05 2012 +0200

    Set correct parent_statement for MemberInitializer
    
    Fixes bug 603056.

 tests/Makefile.am            |    1 +
 tests/structs/bug603056.vala |    9 +++++++++
 vala/valaexpression.vala     |    3 +++
 3 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a647bb5..8392c67 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -71,6 +71,7 @@ TESTS = \
        structs/bug583603.vala \
        structs/bug595587.vala \
        structs/bug596144.vala \
+       structs/bug603056.vala \
        structs/bug606202.vala \
        structs/bug609642.vala \
        structs/bug613513.vala \
diff --git a/tests/structs/bug603056.vala b/tests/structs/bug603056.vala
new file mode 100644
index 0000000..d4646b1
--- /dev/null
+++ b/tests/structs/bug603056.vala
@@ -0,0 +1,9 @@
+public struct Foo {
+        uint8 param;
+}
+
+void main() {
+       bool b = true;
+       var foo = Foo() { param = b ? 10 : 20 };
+       assert (foo.param == 10);
+}
diff --git a/vala/valaexpression.vala b/vala/valaexpression.vala
index dd005af..620086e 100644
--- a/vala/valaexpression.vala
+++ b/vala/valaexpression.vala
@@ -83,12 +83,15 @@ public abstract class Vala.Expression : CodeNode {
                        var expr = parent_node as Expression;
                        var stmt = parent_node as Statement;
                        var local = parent_node as LocalVariable;
+                       var initializer = parent_node as MemberInitializer;
                        if (stmt != null) {
                                return (Statement) parent_node;
                        } else if (expr != null) {
                                return expr.parent_statement;
                        } else if (local != null) {
                                return (Statement) local.parent_node;
+                       } else if (initializer != null) {
+                               return ((Expression)initializer.parent_node).parent_statement;
                        } else {
                                return null;
                        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]