[vala/staging] codegen: Fix property access inside opaque compact class
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Fix property access inside opaque compact class
- Date: Mon, 30 Aug 2021 07:00:11 +0000 (UTC)
commit 4e305e23c4de8e83bf106e2e202f5926c65670e2
Author: Princeton Ferro <princetonferro gmail com>
Date: Sun Aug 29 22:02:26 2021 -0400
codegen: Fix property access inside opaque compact class
Avoid using "priv" when accessing a private or internal field backing a
property of a compact class.
codegen/valaccodememberaccessmodule.vala | 6 ++++--
.../semantic/class-opaque-automatic-property.c-expected | 16 ++++++++++++++--
tests/semantic/class-opaque-automatic-property.vala | 6 ++++++
3 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 88a3d74c9..4e411c73e 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -248,8 +248,10 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
prop.base_property == null &&
prop.base_interface_property == null &&
!(prop.property_type is ArrayType || prop.property_type is DelegateType)) {
- CCodeExpression inst;
- inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
+ CCodeExpression inst = pub_inst;
+ if (!((Class) current_type_symbol).is_compact) {
+ inst = new CCodeMemberAccess.pointer (inst, "priv");
+ }
set_cvalue (expr, new CCodeMemberAccess.pointer (inst, get_ccode_name
(prop.field)));
} else if (!get_ccode_no_accessor_method (prop)) {
string getter_cname;
diff --git a/tests/semantic/class-opaque-automatic-property.c-expected
b/tests/semantic/class-opaque-automatic-property.c-expected
index a60070aeb..fbb7cb85c 100644
--- a/tests/semantic/class-opaque-automatic-property.c-expected
+++ b/tests/semantic/class-opaque-automatic-property.c-expected
@@ -27,12 +27,23 @@ struct _Foo {
VALA_EXTERN void foo_free (Foo * self);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, foo_free)
static void foo_instance_init (Foo * self);
-VALA_EXTERN Foo* foo_new (void);
-VALA_EXTERN gint foo_get_bar (Foo* self);
+VALA_EXTERN void foo_manam (Foo* self);
VALA_EXTERN void foo_set_bar (Foo* self,
gint value);
+VALA_EXTERN gint foo_get_bar (Foo* self);
+VALA_EXTERN Foo* foo_new (void);
static void _vala_main (void);
+void
+foo_manam (Foo* self)
+{
+ gint _tmp0_;
+ g_return_if_fail (self != NULL);
+ foo_set_bar (self, 23);
+ _tmp0_ = self->_bar;
+ _vala_assert (_tmp0_ == 23, "bar == 23");
+}
+
Foo*
foo_new (void)
{
@@ -79,6 +90,7 @@ _vala_main (void)
gint _tmp2_;
_tmp0_ = foo_new ();
foo = _tmp0_;
+ foo_manam (foo);
foo_set_bar (foo, 42);
_tmp1_ = foo_get_bar (foo);
_tmp2_ = _tmp1_;
diff --git a/tests/semantic/class-opaque-automatic-property.vala
b/tests/semantic/class-opaque-automatic-property.vala
index 8400a78b5..893d03f42 100644
--- a/tests/semantic/class-opaque-automatic-property.vala
+++ b/tests/semantic/class-opaque-automatic-property.vala
@@ -1,10 +1,16 @@
[Compact (opaque = true)]
public class Foo {
public int bar { get; set; }
+
+ public void manam () {
+ bar = 23;
+ assert (bar == 23);
+ }
}
void main () {
var foo = new Foo ();
+ foo.manam ();
foo.bar = 42;
assert (foo.bar == 42);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]