[vala/0.52] vala: Require lvalue access of delegate target/destroy "fields"
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.52] vala: Require lvalue access of delegate target/destroy "fields"
- Date: Thu, 17 Feb 2022 08:46:58 +0000 (UTC)
commit b2c656d0520de44c0053db5238cbd00136847cc3
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Jan 16 19:25:51 2022 +0100
vala: Require lvalue access of delegate target/destroy "fields"
In addition to c054da918a40f8ef93c1a006034fb6ab4717c135
See https://gitlab.gnome.org/GNOME/vala/issues/857
codegen/valaccodememberaccessmodule.vala | 4 ++--
tests/Makefile.am | 1 +
tests/delegates/member-target-destroy-2.vala | 20 ++++++++++++++++++++
vala/valamemberaccess.vala | 8 ++++++++
4 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 455827b26..fa412ae5f 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -140,14 +140,14 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
Report.error (expr.source_reference, "unsupported use of target field of
delegate without target");
}
CCodeExpression delegate_target_destroy_notify;
- set_cvalue (expr, get_delegate_target_cexpression (expr.inner, out
delegate_target_destroy_notify));
+ set_cvalue (expr, get_delegate_target_cexpression (expr.inner, out
delegate_target_destroy_notify) ?? new CCodeConstant ("NULL"));
} else if (expr.symbol_reference is DelegateDestroyField) {
if (!((DelegateType) expr.inner.value_type).delegate_symbol.has_target) {
Report.error (expr.source_reference, "unsupported use of destroy field of
delegate without target");
}
CCodeExpression delegate_target_destroy_notify;
get_delegate_target_cexpression (expr.inner, out delegate_target_destroy_notify);
- set_cvalue (expr, delegate_target_destroy_notify);
+ set_cvalue (expr, delegate_target_destroy_notify ?? new CCodeConstant ("NULL"));
} else if (expr.symbol_reference is GenericDupField) {
set_cvalue (expr, get_dup_func_expression (expr.inner.value_type,
expr.source_reference));
} else if (expr.symbol_reference is GenericDestroyField) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c3f6dc613..f68930da6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -431,6 +431,7 @@ TESTS = \
delegates/lambda-outer-constant.test \
delegates/lambda-shared-closure.vala \
delegates/member-target-destroy.vala \
+ delegates/member-target-destroy-2.vala \
delegates/reference_transfer.vala \
delegates/return-array-null-terminated.vala \
delegates/wrapper.vala \
diff --git a/tests/delegates/member-target-destroy-2.vala b/tests/delegates/member-target-destroy-2.vala
new file mode 100644
index 000000000..62ecd263a
--- /dev/null
+++ b/tests/delegates/member-target-destroy-2.vala
@@ -0,0 +1,20 @@
+delegate void FooFunc ();
+
+void bar (string s) {
+ assert (s == "foo");
+}
+
+void foo (owned FooFunc func) {
+ assert (func.target == "foo");
+ assert (func.destroy == g_free);
+ func ();
+}
+
+void main () {
+ FooFunc func = (FooFunc) bar;
+
+ func.target = "foo".dup ();
+ func.destroy = g_free;
+
+ foo ((owned) func);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index b68676e44..5f90a8449 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -1093,6 +1093,14 @@ public class Vala.MemberAccess : Expression {
}
}
+ if (symbol_reference is DelegateTargetField || symbol_reference is DelegateDestroyField) {
+ inner.lvalue = true;
+ if (ma != null) {
+ ma.lvalue = true;
+ ma.check_lvalue_access ();
+ }
+ }
+
if (symbol_reference is Method && ((Method) symbol_reference).get_attribute
("DestroysInstance") != null) {
unowned Class? cl = ((Method) symbol_reference).parent_symbol as Class;
if (cl != null && cl.is_compact && ma != null) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]