]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix access to type parameters
authorLorenz Wildberg <lorenz@wild-fisch.de>
Mon, 24 Jul 2023 20:44:52 +0000 (22:44 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 31 Jan 2024 17:51:28 +0000 (18:51 +0100)
codegen/valaccodebasemodule.vala
vala/valatypeparameter.vala

index ffdfbd143bebb41b60a8069d81270fab025b4e9c..e733faa60e7a7460d08fca6f092780661fdb4bc2 100644 (file)
@@ -2980,8 +2980,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                Report.error (type.source_reference, "static type-parameter `%s' can not be used in runtime context", type.type_symbol.get_full_name ());
                                return new CCodeInvalidExpression();
                        }
-                       string identifier = get_ccode_type_id (type_parameter);
-                       return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
+                       if (!type_parameter.no_generic_args) {
+                               string identifier = get_ccode_type_id (type_parameter);
+                               return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
+                       } else {
+                               var constrained_type = type_parameter.get_constrained_type ();
+                               return new CCodeIdentifier (get_ccode_type_id (constrained_type));
+                       }
                } else {
                        string type_id = get_ccode_type_id (type);
                        if (type_id == "") {
@@ -2998,8 +3003,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return new CCodeIdentifier ("g_error_copy");
                } else if (type is GenericType) {
                        var type_parameter = ((GenericType) type).type_parameter;
-                       string identifier = get_ccode_copy_function (type_parameter);
-                       return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
+                       if (!type_parameter.no_generic_args) {
+                               string identifier = get_ccode_copy_function (type_parameter);
+                               return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
+                       } else {
+                               var constrained_type = type_parameter.get_constrained_type ();
+                               return new CCodeIdentifier (get_ccode_ref_function (constrained_type.type_symbol));
+                       }
                } else if (type.type_symbol != null) {
                        string dup_function;
                        unowned Class? cl = type.type_symbol as Class;
@@ -3552,8 +3562,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        return new CCodeIdentifier ("g_error_free");
                } else if (type is GenericType) {
                        var type_parameter = ((GenericType) type).type_parameter;
-                       string identifier = get_ccode_destroy_function (type_parameter);
-                       return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
+                       if (!type_parameter.no_generic_args) {
+                               string identifier = get_ccode_destroy_function (type_parameter);
+                               return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
+                       } else {
+                               var constrained_type = type_parameter.get_constrained_type ();
+                               return new CCodeIdentifier (get_ccode_unref_function ((ObjectTypeSymbol) constrained_type.type_symbol));
+                       }
                } else if (type.type_symbol != null) {
                        string unref_function;
                        if (type is ReferenceType) {
index 95a8c1745e0e9de889f5ce74daf20acd24a91146..a377fe0ce9c67cc5022cfb6c34a681bcf9a984d6 100644 (file)
@@ -171,8 +171,8 @@ public class Vala.TypeParameter : TypeSymbol {
                        error = true;
                }
 
-               if (no_generic_args && !has_type_constraints ()) {
-                       Report.error (source_reference, "type parameters need to be constrained for using `no_generic_args'");
+               if (no_generic_args && (!has_type_constraints () || !(get_constrained_type ().type_symbol is ObjectTypeSymbol))) {
+                       Report.error (source_reference, "type parameters need to be constrained with an object type for using `no_generic_args'");
                        error = true;
                }