consider switch statements when releasing local variables, fixes bug
authorMathias Hasselmann <mathias.hasselmann@gmx.de>
Tue, 21 Aug 2007 07:40:14 +0000 (07:40 +0000)
committerMathias Hasselmann <hasselmm@src.gnome.org>
Tue, 21 Aug 2007 07:40:14 +0000 (07:40 +0000)
2007-08-21 Mathias Hasselmann <mathias.hasselmann@gmx.de>

* gobject/valacodegenerator.vala, vala/valaswitchsection.vala,
vala/valaswitchstatement.vala: consider switch statements
when releasing local variables, fixes bug 467896
* tests/Makefile.am, tests/test-035.*: test for that bug

svn path=/trunk/; revision=493

ChangeLog
gobject/valacodegenerator.vala
tests/Makefile.am
tests/test-035.out [new file with mode: 0644]
tests/test-035.vala [new file with mode: 0644]
vala/valaswitchsection.vala
vala/valaswitchstatement.vala

index 7ff0333..0d434f5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-08-21  Mathias Hasselmann  <mathias.hasselmann@gmx.de>
+
+       * gobject/valacodegenerator.vala, vala/valaswitchsection.vala,
+       vala/valaswitchstatement.vala: consider switch statements
+       when releasing local variables, fixes bug 467896
+       * tests/Makefile.am, tests/test-035.*: test for that bug
+
 2007-08-20  Jürg Billeter  <j@bitron.ch>
 
        * vala/valasemanticanalyzer.vala, vala/valathrowstatement.vala,
index 5bbbeb6..bd79f7b 100644 (file)
@@ -1634,7 +1634,8 @@ public class Vala.CodeGenerator : CodeVisitor {
                
                if (stop_at_loop) {
                        if (b.parent_node is DoStatement || b.parent_node is WhileStatement ||
-                           b.parent_node is ForStatement || b.parent_node is ForeachStatement) {
+                           b.parent_node is ForStatement || b.parent_node is ForeachStatement ||
+                           b.parent_node is SwitchStatement) {
                                return;
                        }
                }
index 34bb5a2..5b7cdfd 100644 (file)
@@ -67,6 +67,7 @@ TESTS = \
        test-032.vala \
        test-033.vala \
        test-034.vala \
+       test-035.vala \
        $(NULL)
 
 EXTRA_DIST = \
@@ -105,6 +106,7 @@ EXTRA_DIST = \
        test-032.vala \
        test-033.vala \
        test-034.vala \
+       test-035.vala \
        test-001.out \
        test-002.out \
        test-003.out \
@@ -139,6 +141,7 @@ EXTRA_DIST = \
        test-032.out \
        test-033.out \
        test-034.out \
+       test-035.out \
        \
        testenchant.stamp \
        testenchant.vala \
diff --git a/tests/test-035.out b/tests/test-035.out
new file mode 100644 (file)
index 0000000..a2633c9
--- /dev/null
@@ -0,0 +1,3 @@
+before switch: Hello World
+within switch: Hello World
+behind switch: Hello World
diff --git a/tests/test-035.vala b/tests/test-035.vala
new file mode 100644 (file)
index 0000000..8e41184
--- /dev/null
@@ -0,0 +1,18 @@
+using GLib;
+
+class SwitchTest {
+    static void main () {
+        var foo = "Hello World";
+        var bar = 0;
+
+        stdout.printf ("before switch: %s\n", foo);
+
+       switch (bar) {
+           case 0:
+               stdout.printf ("within switch: %s\n", foo);
+               break;
+       }
+
+        stdout.printf ("behind switch: %s\n", foo);
+    }
+}
index 6b6cf5b..a85773e 100644 (file)
@@ -26,7 +26,7 @@ using Gee;
 /**
  * Represents a switch section in the source code.
  */
-public class Vala.SwitchSection : CodeNode {
+public class Vala.SwitchSection : Block {
        private Gee.List<SwitchLabel> labels = new ArrayList<SwitchLabel> ();
        private Gee.List<Statement> statement_list = new ArrayList<Statement> ();
 
@@ -90,10 +90,13 @@ public class Vala.SwitchSection : CodeNode {
                        label.accept (visitor);
                }
 
+               visitor.visit_begin_block (this);
+
                foreach (Statement st in statement_list) {
                        st.accept (visitor);
                }
                
                visitor.visit_switch_section (this);
+               visitor.visit_end_block (this);
        }
 }
index 40a1a1d..0a452be 100644 (file)
@@ -59,6 +59,7 @@ public class Vala.SwitchStatement : CodeNode, Statement {
         * @param section a switch section
         */
        public void add_section (SwitchSection! section) {
+               section.parent_node = this;
                sections.add (section);
        }