]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Use GLib.Object as type-argument for GLib.ListModel/ListStore if none is given
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 8 Apr 2023 13:50:53 +0000 (15:50 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 17 Apr 2023 19:01:06 +0000 (21:01 +0200)
vala/valadatatype.vala
vala/valasemanticanalyzer.vala

index 897eaf72c391999acf36d3f6849b3f6769889660..d75eee62a48b97df5c009024ef4fb36a56acb095 100644 (file)
@@ -692,9 +692,17 @@ public abstract class Vala.DataType : CodeNode {
                }
 
                if ((!allow_none || n_type_args > 0) && n_type_args < expected_n_type_args) {
-                       error = true;
-                       Report.error (source_reference, "too few type arguments for `%s'", type_symbol.to_string ());
-                       return false;
+                       if (n_type_args == 0 && type_symbol != null
+                           && (type_symbol == context.analyzer.glistmodel_type || type_symbol == context.analyzer.gliststore_type)) {
+                               Report.notice (source_reference, "`%s' requires a type argument, defaulting to `GLib.Object'", type_symbol.to_string ());
+                               var type = new ObjectType (context.analyzer.object_type, source_reference);
+                               type.value_owned = true;
+                               add_type_argument (type);
+                       } else {
+                               error = true;
+                               Report.error (source_reference, "too few type arguments for `%s'", type_symbol.to_string ());
+                               return false;
+                       }
                } else if ((!allow_none || n_type_args > 0) && n_type_args > expected_n_type_args) {
                        error = true;
                        Report.error (source_reference, "too many type arguments for `%s'", type_symbol.to_string ());
index a5076a2fef72c09f24617893a703a340b8d17947..55267576e3d96e034386fbf8ffa1e16269c7a84b 100644 (file)
@@ -172,6 +172,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public DataType delegate_target_type;
        public DelegateType delegate_target_destroy_type;
        public DelegateType generics_dup_func_type;
+       public Interface? glistmodel_type;
+       public Class? gliststore_type;
 
        Delegate destroy_notify;
 
@@ -238,6 +240,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 
                        gsource_type = (Class) glib_ns.scope.lookup ("Source");
 
+                       glistmodel_type = glib_ns.scope.lookup ("ListModel") as Interface;
+                       gliststore_type = glib_ns.scope.lookup ("ListStore") as Class;
+
                        delegate_target_type = new StructValueType ((Struct) glib_ns.scope.lookup ("pointer"));
                        destroy_notify = (Delegate) glib_ns.scope.lookup ("DestroyNotify");
                        delegate_target_destroy_type = new DelegateType (destroy_notify);