From: Rico Tzschichholz Date: Sun, 7 Mar 2021 16:19:01 +0000 (+0100) Subject: codegen: Report error for missing type-arguments of HashTable (de)serialization X-Git-Tag: 0.51.91~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=208a41fcc94a77c64bfec0e6bb5f17cd2d1d36e7;p=thirdparty%2Fvala.git codegen: Report error for missing type-arguments of HashTable (de)serialization Fixes https://gitlab.gnome.org/GNOME/vala/issues/1147 --- diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala index 808af51b1..91a66881a 100644 --- a/codegen/valagvariantmodule.vala +++ b/codegen/valagvariantmodule.vala @@ -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); diff --git a/tests/Makefile.am b/tests/Makefile.am index 7a52be5fc..3836fef78 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..2ce71ded5 --- /dev/null +++ b/tests/basic-types/gvariants-hashtable-missing-type-arguments.test @@ -0,0 +1,12 @@ +Invalid Code + +void main () { + { + HashTable foo = null; + Variant v = foo; + } + { + Variant v = null; + var foo = (HashTable) v; + } +}