]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix foreach on inline allocated arrays
authorLuca Bruno <lucabru@src.gnome.org>
Sat, 18 Jun 2011 10:21:14 +0000 (12:21 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Sat, 18 Jun 2011 10:23:25 +0000 (12:23 +0200)
Fixes bug 652549.

codegen/valaccodecontrolflowmodule.vala
tests/Makefile.am
tests/control-flow/bug652549.vala [new file with mode: 0644]
vala/valaforeachstatement.vala

index b939bed1cc24ec0e4c2d7a194191bd92b754fbb0..46c8ed13fdbeffbe120c84e9fb9ce4a2ae87a91f 100644 (file)
@@ -222,11 +222,12 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
                ccode.open_block ();
 
                var collection_backup = stmt.collection_variable;
-               var collection_type = collection_backup.variable_type.copy ();
+               var collection_type = collection_backup.variable_type;
 
                var array_type = collection_type as ArrayType;
                if (array_type != null) {
                        // avoid assignment issues
+                       array_type.inline_allocated = false;
                        array_type.fixed_length = false;
                }
 
index a4b1beddd80a091b3f00b98b99988999bc102732..9819401e161a89d524bbd366711a2d5a97c4d859 100644 (file)
@@ -47,6 +47,7 @@ TESTS = \
        control-flow/foreach.vala \
        control-flow/switch.vala \
        control-flow/sideeffects.vala \
+       control-flow/bug652549.vala \
        enums/enums.vala \
        structs/structs.vala \
        structs/gvalue.vala \
diff --git a/tests/control-flow/bug652549.vala b/tests/control-flow/bug652549.vala
new file mode 100644 (file)
index 0000000..ac801af
--- /dev/null
@@ -0,0 +1,6 @@
+void main () {
+       int foo[2] = {1,1};
+       foreach (var bar in foo) {
+               assert (bar == 1);
+       }
+}
index 2ce466d9557f2e8aa8333c89fe485e44e5b5ef6c..a518a2beedc23b0698986a8c5d033c5eef385ebc 100644 (file)
@@ -374,7 +374,7 @@ public class Vala.ForeachStatement : Block {
 
                context.analyzer.current_symbol = context.analyzer.current_symbol.parent_symbol;
 
-               collection_variable = new LocalVariable (collection_type, "%s_collection".printf (variable_name));
+               collection_variable = new LocalVariable (collection_type.copy (), "%s_collection".printf (variable_name));
 
                add_local_variable (collection_variable);
                collection_variable.active = true;