]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Report error for missing type-arguments of HashTable (de)serialization
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 7 Mar 2021 16:19:01 +0000 (17:19 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 7 Mar 2021 16:25:59 +0000 (17:25 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1147

codegen/valagvariantmodule.vala
tests/Makefile.am
tests/basic-types/gvariants-hashtable-missing-type-arguments.test [new file with mode: 0644]

index 808af51b1f1b2328fc135641039df259b145d5bc..91a66881a3dab1a5989a5f09b48aec266c6f328c 100644 (file)
@@ -474,7 +474,10 @@ public class Vala.GVariantModule : GValueModule {
                string value_name = "_tmp%d_".printf (next_temp_var_id++);
 
                var type_args = type.get_type_arguments ();
-               assert (type_args.size == 2);
+               if (type_args.size != 2) {
+                       Report.error (type.source_reference, "Missing type-arguments for GVariant deserialization of `%s'", type.type_symbol.get_full_name ());
+                       return new CCodeInvalidExpression ();
+               }
                var key_type = type_args.get (0);
                var value_type = type_args.get (1);
 
@@ -803,7 +806,10 @@ public class Vala.GVariantModule : GValueModule {
                string value_name = "_tmp%d_".printf (next_temp_var_id++);
 
                var type_args = type.get_type_arguments ();
-               assert (type_args.size == 2);
+               if (type_args.size != 2) {
+                       Report.error (type.source_reference, "Missing type-arguments for GVariant serialization of `%s'", type.type_symbol.get_full_name ());
+                       return new CCodeInvalidExpression ();
+               }
                var key_type = type_args.get (0);
                var value_type = type_args.get (1);
 
index 7a52be5fc0ba813e86c379c00775672ee6551af6..3836fef781a9ac8af650e13a9910c08876276da4 100644 (file)
@@ -59,6 +59,7 @@ TESTS = \
        basic-types/glists.vala \
        basic-types/gptrarray.vala \
        basic-types/gvariants.vala \
+       basic-types/gvariants-hashtable-missing-type-arguments.test \
        basic-types/gvariants-unboxing-safe.vala \
        basic-types/null.vala \
        basic-types/bug570846.test \
diff --git a/tests/basic-types/gvariants-hashtable-missing-type-arguments.test b/tests/basic-types/gvariants-hashtable-missing-type-arguments.test
new file mode 100644 (file)
index 0000000..2ce71de
--- /dev/null
@@ -0,0 +1,12 @@
+Invalid Code
+
+void main () {
+       {
+               HashTable foo = null;
+               Variant v = foo;
+       }
+       {
+               Variant v = null;
+               var foo = (HashTable) v;
+       }
+}