]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Don't generate a hashmap, if >0 args are generic or array
authorJCWasmx86 <JCWasmx86@t-online.de>
Sat, 4 Jun 2022 17:37:22 +0000 (19:37 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 29 Apr 2023 19:00:17 +0000 (21:00 +0200)
dbusgen/valadbusvariantmodule.vala

index d8503ae7180f88255731e9cd2b35b121ab16cef4..be2aa6856ed76ba8c4843cc6e3b7444843a1528c 100644 (file)
@@ -160,7 +160,22 @@ public class Vala.DBusVariantModule {
                return get_complex_type (type);
        }
 
+       private bool invalid_generic_type (VariantType type) {
+               return  type.equal (VariantType.BOOLEAN)
+                               || type.equal (VariantType.BYTE)
+                               || type.equal (VariantType.INT16)
+                               || type.equal (VariantType.UINT16)
+                               || type.equal (VariantType.INT32)
+                               || type.equal (VariantType.UINT32)
+                               || type.equal (VariantType.INT64)
+                               || type.equal (VariantType.UINT64)
+                               || type.equal (VariantType.DOUBLE);
+       }
+
        private DataType? get_complex_type (VariantType type) {
+               // If we were able to interpret it, but it is false vala syntax
+               // E.g. generics with arrays/primitive types
+               var skipped_generation = false;
                if (type.equal (VariantType.OBJECT_PATH_ARRAY)) {
                        return object_path_array_type.copy ();
                } else if (type.equal (VariantType.BYTESTRING)) {
@@ -175,9 +190,10 @@ public class Vala.DBusVariantModule {
                        // TODO: Warn about arrays in generics
                        if (element.equal (VariantType.DICTIONARY) || element.is_dict_entry ()) {
                                var res = dictionary_type.copy ();
+                               var invalid_generic_arg = invalid_generic_type (element.key()) || invalid_generic_type (element.value ());
                                var key = get_variant_type (element.key ());
                                var value = get_variant_type (element.value ());
-                               if (key != null && value != null && !(key is ArrayType) && !(value is ArrayType)) {
+                               if (key != null && value != null && !(key is ArrayType) && !(value is ArrayType) && !invalid_generic_arg) {
                                        res.add_type_argument (key);
                                        res.add_type_argument (value);
                                        return res;
@@ -194,8 +210,9 @@ public class Vala.DBusVariantModule {
                        // TODO: Emit structure
                }
 
-               Report.warning (null, "Unresolved type: %s".printf ((string) type.peek_string ()));
-
+               if (!skipped_generation) {
+                       Report.warning (null, "Unresolved type: %s".printf ((string) type.peek_string ()));
+               }
                return null;
 
                if (type.equal (VariantType.DICT_ENTRY) || type.is_dict_entry ()) {