From: Mathias Hasselmann Date: Tue, 21 Aug 2007 07:40:14 +0000 (+0000) Subject: consider switch statements when releasing local variables, fixes bug X-Git-Tag: VALA_0_1_3~62 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e057df148aee99cb4540c8f2e372b1d9143d743f;p=platform%2Fupstream%2Fvala.git consider switch statements when releasing local variables, fixes bug 2007-08-21 Mathias Hasselmann * 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 --- diff --git a/ChangeLog b/ChangeLog index 7ff0333..0d434f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-08-21 Mathias Hasselmann + + * 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 * vala/valasemanticanalyzer.vala, vala/valathrowstatement.vala, diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index 5bbbeb6..bd79f7b 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -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; } } diff --git a/tests/Makefile.am b/tests/Makefile.am index 34bb5a2..5b7cdfd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 0000000..a2633c9 --- /dev/null +++ b/tests/test-035.out @@ -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 index 0000000..8e41184 --- /dev/null +++ b/tests/test-035.vala @@ -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); + } +} diff --git a/vala/valaswitchsection.vala b/vala/valaswitchsection.vala index 6b6cf5b..a85773e 100644 --- a/vala/valaswitchsection.vala +++ b/vala/valaswitchsection.vala @@ -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 labels = new ArrayList (); private Gee.List statement_list = new ArrayList (); @@ -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); } } diff --git a/vala/valaswitchstatement.vala b/vala/valaswitchstatement.vala index 40a1a1d..0a452be 100644 --- a/vala/valaswitchstatement.vala +++ b/vala/valaswitchstatement.vala @@ -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); }