[vala/0.52] vala: Don't restrict element type of GLib.Array



commit 0d7d1728eeaeefb201de12dc6724dc52bff8ce4e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Sep 15 14:38:19 2021 +0200

    vala: Don't restrict element type of GLib.Array
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1227

 tests/basic-types/garray.vala  | 25 +++++++++++++++++++++++++
 vala/valasemanticanalyzer.vala |  6 ++++++
 2 files changed, 31 insertions(+)
---
diff --git a/tests/basic-types/garray.vala b/tests/basic-types/garray.vala
index 9f09560a7..8732fa42f 100644
--- a/tests/basic-types/garray.vala
+++ b/tests/basic-types/garray.vala
@@ -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 ();
 }
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index ff6616449..141d19cdd 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -1293,6 +1293,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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]