extend the array test with an array of structs declared through the "var"
authorRaffaele Sandrini <raffaele@sandrini.ch>
Sun, 3 Feb 2008 21:22:28 +0000 (21:22 +0000)
committerRaffaele Sandrini <rasa@src.gnome.org>
Sun, 3 Feb 2008 21:22:28 +0000 (21:22 +0000)
2008-02-03  Raffaele Sandrini  <raffaele@sandrini.ch>

        * tests/arrays.vala: extend the array test with an array of structs
          declared through the "var" keyword
        * vala/valasemanticanalyzer.vala: fix a memory management bug with
          arrays of struct elements

svn path=/trunk/; revision=958

ChangeLog
tests/arrays.vala
vala/valasemanticanalyzer.vala

index adcf7a9..6bfeb88 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-03  Raffaele Sandrini  <raffaele@sandrini.ch>
+
+       * tests/arrays.vala: extend the array test with an array of structs
+         declared through the "var" keyword
+       * vala/valasemanticanalyzer.vala: fix a memory management bug with
+         arrays of struct elements
+
 2008-02-03  Jürg Billeter  <j@bitron.ch>
 
        * vapigen/valagidlparser.vala: set requires_null_check for nullable
index c031b65..c752b03 100644 (file)
@@ -166,6 +166,12 @@ class Maman.Foo : Object {
                stdout.printf ("\n");
        }
 
+       static void test_array_var_creation_with_structs () {
+               var ca = new char[16];
+               ca[5] = 'a';
+               assert (ca[5] == 'a');
+       }
+
        static void test_array_creation_side_effects () {
                int i = 5;
                var arr = new int[i++];
@@ -241,6 +247,8 @@ class Maman.Foo : Object {
                test_element_access ();
 
                test_array_length_of_array_constants ();
+
+               test_array_var_creation_with_structs ();
        }
        
        public static int inc () {
index 81d1c6c..0df6db6 100644 (file)
@@ -1217,12 +1217,18 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        return;
                }
 
+               /* arrays of struct type elements do not take ownership since they are copied into the array */
+               if (expr.element_type.data_type is Struct) {
+                       expr.element_type.takes_ownership = false;
+               } else {
+                       expr.element_type.takes_ownership = true;
+               }
+
                expr.static_type = new ArrayType (expr.element_type, expr.rank);
                expr.static_type.transfers_ownership = true;
                expr.static_type.takes_ownership = true;
 
                expr.static_type.add_type_argument (expr.element_type);
-               expr.element_type.takes_ownership = true;
        }
 
        public override void visit_boolean_literal (BooleanLiteral! expr) {