]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't restrict element type of GLib.Array
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 15 Sep 2021 12:38:19 +0000 (14:38 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 23 Sep 2021 08:18:09 +0000 (10:18 +0200)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1227

tests/basic-types/garray.vala
vala/valasemanticanalyzer.vala

index 9f09560a7c8b021ee8aedfe9ca83f1eb5e999197..8732fa42fc73ce49075be69105ad6fa2ad4ca130 100644 (file)
@@ -89,9 +89,34 @@ void test_object_garray () {
        assert (foo.ref_count == 1);
 }
 
+unowned Array<Value> check_gvalue_garray (Array<Value> vals) {
+       assert (vals.index (0) == "foo");
+       assert (vals.index (1) == 42);
+       assert (vals.index (2) == 3.1415);
+       return vals;
+}
+
+void test_gvalue_garray () {
+       {
+               var foo = new Array<Value> ();
+               foo.append_val ("foo");
+               foo.append_val (42);
+               foo.append_val (3.1415);
+               check_gvalue_garray (foo);
+       }
+       {
+               Array<Value> foo = new Array<Value> ();
+               foo.append_val ("foo");
+               foo.append_val (42);
+               foo.append_val (3.1415);
+               check_gvalue_garray (foo);
+       }
+}
+
 void main () {
        test_garray ();
        test_int_garray ();
        test_struct_garray ();
        test_object_garray ();
+       test_gvalue_garray ();
 }
index 46857bd52d9abf7424d9b0b60fedd4ad33e3bb06..de9096775bab8d93132dbadcbac1b1018d4d85f5 100644 (file)
@@ -1333,6 +1333,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        }
 
        public void check_type (DataType type) {
+               // Allow any type-argument for GLib.Array
+               if (context != null && context.profile == Profile.GOBJECT
+                   && type.type_symbol == garray_type.type_symbol) {
+                       return;
+               }
+
                foreach (var type_arg in type.get_type_arguments ()) {
                        check_type (type_arg);
                        check_type_argument (type_arg);