]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Owned property accessors are not allowed for non-null simple types
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 21 Mar 2023 10:14:49 +0000 (11:14 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 21 Mar 2023 10:14:49 +0000 (11:14 +0100)
Additionally drop invalid g_value_take_* references for enums

codegen/valaccodeattribute.vala
tests/Makefile.am
tests/objects/property-owned-simple-type.test [new file with mode: 0644]
vala/valapropertyaccessor.vala

index 3901e65d980a9dc5986e56028b3005f20636108f..74a366524be82ea19e1825c509b59e692ad1ebfc 100644 (file)
@@ -1337,21 +1337,6 @@ public class Vala.CCodeAttribute : AttributeCache {
                        } else {
                                return "g_value_take_boxed";
                        }
-               } else if (sym is Enum) {
-                       unowned Enum en = (Enum) sym;
-                       if (get_ccode_has_type_id (en)) {
-                               if (en.is_flags) {
-                                       return "g_value_take_flags";
-                               } else {
-                                       return "g_value_take_enum";
-                               }
-                       } else {
-                               if (en.is_flags) {
-                                       return "g_value_take_uint";
-                               } else {
-                                       return "g_value_take_int";
-                               }
-                       }
                } else if (sym is ErrorDomain) {
                        return "g_value_take_boxed";
                } else if (sym is Interface) {
index 9b005ce7613c974c370f811ae138f78f455d0680..6f4c5a75201a2062d3d68f02d1964f955d2fa9e0 100644 (file)
@@ -568,6 +568,7 @@ TESTS = \
        objects/property-error.vala \
        objects/property-notify.vala \
        objects/property-notify-owned-getter.vala \
+       objects/property-owned-simple-type.test \
        objects/property-ownership.vala \
        objects/property-read-only-auto.vala \
        objects/property-read-only-member-write.test \
diff --git a/tests/objects/property-owned-simple-type.test b/tests/objects/property-owned-simple-type.test
new file mode 100644 (file)
index 0000000..d75565b
--- /dev/null
@@ -0,0 +1,12 @@
+Invalid Code
+
+enum Bar {
+       FOO
+}
+
+class Foo : Object {
+       public Bar bar { owned get; owned set; }
+}
+
+void main () {
+}
index 0fbf4d32f508182cc192d6f939b09951991ca46d..72e5ce675ac93b1aa77ee47e338c78018b6a91fd 100644 (file)
@@ -218,6 +218,12 @@ public class Vala.PropertyAccessor : Subroutine {
                        return false;
                }
 
+               if (value_type.value_owned && value_type.is_non_null_simple_type ()) {
+                       error = true;
+                       Report.error (source_reference, "`owned' accessor not allowed for specified property type");
+                       return false;
+               }
+
                if (context.profile == Profile.POSIX && construction) {
                        error = true;
                        Report.error (source_reference, "`construct' is not supported in POSIX profile");