From f8c0ce38c6954069a81561bff8207bf43a81c10f Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Tue, 21 Mar 2023 11:14:49 +0100 Subject: vala: Owned property accessors are not allowed for non-null simple types Additionally drop invalid g_value_take_* references for enums --- codegen/valaccodeattribute.vala | 15 --------------- tests/Makefile.am | 1 + tests/objects/property-owned-simple-type.test | 12 ++++++++++++ vala/valapropertyaccessor.vala | 6 ++++++ 4 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 tests/objects/property-owned-simple-type.test diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala index 3901e65d9..74a366524 100644 --- a/codegen/valaccodeattribute.vala +++ b/codegen/valaccodeattribute.vala @@ -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) { diff --git a/tests/Makefile.am b/tests/Makefile.am index 9b005ce76..6f4c5a752 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..d75565bfa --- /dev/null +++ b/tests/objects/property-owned-simple-type.test @@ -0,0 +1,12 @@ +Invalid Code + +enum Bar { + FOO +} + +class Foo : Object { + public Bar bar { owned get; owned set; } +} + +void main () { +} diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala index 0fbf4d32f..72e5ce675 100644 --- a/vala/valapropertyaccessor.vala +++ b/vala/valapropertyaccessor.vala @@ -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"); -- cgit v1.2.1