]> 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>
Sat, 13 Mar 2021 20:35:17 +0000 (21:35 +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 bd45a77387c3808fa92723b801a2ebaf60795a66..d4719b9068339d9d2598490de4425b9b568cb2bc 100644 (file)
@@ -468,7 +468,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'".printf (type.type_symbol.get_full_name ()));
+                       return new CCodeInvalidExpression ();
+               }
                var key_type = type_args.get (0);
                var value_type = type_args.get (1);
 
@@ -785,7 +788,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'".printf (type.type_symbol.get_full_name ()));
+                       return new CCodeInvalidExpression ();
+               }
                var key_type = type_args.get (0);
                var value_type = type_args.get (1);
 
index a1a6ccba211b8716dc0730f2402632b17707a324..4c97b72a739e486b0d8a38f2d43b8b993a7a52b1 100644 (file)
@@ -58,6 +58,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;
+       }
+}