]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Return CCodeInvalidExpression instead of null
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 13 Apr 2023 06:25:02 +0000 (08:25 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 13 Apr 2023 06:48:53 +0000 (08:48 +0200)
This fixes the following criticals:

  vala_ccode_cast_expression_construct: assertion 'expr != NULL' failed
  vala_ccode_function_call_add_argument: assertion 'expr != NULL' failed

Remove dead code, this is already handled in get_dup_func_expression()

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/semantic/interface-prerequisite-missing-class.test [new file with mode: 0644]

index 51d40271295cf24cb8e60e678c1cf288d70f3661..d1e665747d98a5d067249591f1f20795efffd97b 100644 (file)
@@ -3519,7 +3519,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                        unref_function = get_ccode_unref_function ((ObjectTypeSymbol) type.type_symbol);
                                        if (type.type_symbol is Interface && unref_function == null) {
                                                Report.error (type.source_reference, "missing class prerequisite for interface `%s', add GLib.Object to interface declaration if unsure", type.type_symbol.get_full_name ());
-                                               return null;
+                                               return new CCodeInvalidExpression ();
                                        }
                                } else {
                                        if (get_ccode_is_gboxed (type.type_symbol)) {
@@ -6296,10 +6296,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                if (!gvalue_boxing && !gvariant_boxing && target_type.value_owned && (!type.value_owned || boxing || unboxing || array_needs_copy) && requires_copy (target_type) && !(type is NullType)) {
                        // need to copy value
                        var copy = (GLibValue) copy_value (result, node);
-                       if (target_type.type_symbol is Interface && copy == null) {
-                               Report.error (node.source_reference, "missing class prerequisite for interface `%s', add GLib.Object to interface declaration if unsure", target_type.type_symbol.get_full_name ());
-                               return result;
-                       }
+
                        // need to free old array after copying it
                        if (array_needs_copy && requires_destroy (type)) {
                                result.value_type = type.copy ();
index 2e22aa6db551d084b3920f88a68a1644049fdc9f..b7a46cb31731e2c205dd7a5ae38361b5a9b22b38 100644 (file)
@@ -1191,6 +1191,7 @@ TESTS = \
        semantic/initializer-unknown-type.test \
        semantic/interface-prerequisite-invalid.test \
        semantic/interface-prerequisite-less-accessible.test \
+       semantic/interface-prerequisite-missing-class.test \
        semantic/interface-prerequisite-multiple.test \
        semantic/interface-prerequisite-too-few-type-arguments.test \
        semantic/interface-prerequisite-too-many-type-arguments.test \
diff --git a/tests/semantic/interface-prerequisite-missing-class.test b/tests/semantic/interface-prerequisite-missing-class.test
new file mode 100644 (file)
index 0000000..3e4a9e3
--- /dev/null
@@ -0,0 +1,11 @@
+Invalid Code
+
+interface IFoo {
+}
+
+class Foo<T> {
+}
+
+void main () {
+       var foo = new Foo<IFoo> ();
+}