[vala/staging] codegen: Report error for missing type-arguments of HashTable (de)serialization



commit 208a41fcc94a77c64bfec0e6bb5f17cd2d1d36e7
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Mar 7 17:19:01 2021 +0100

    codegen: Report error for missing type-arguments of HashTable (de)serialization
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1147

 codegen/valagvariantmodule.vala                              | 10 ++++++++--
 tests/Makefile.am                                            |  1 +
 .../gvariants-hashtable-missing-type-arguments.test          | 12 ++++++++++++
 3 files changed, 21 insertions(+), 2 deletions(-)
---
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;
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]