[vala/0.48] codegen: Fix assignment of casted struct value to property
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.48] codegen: Fix assignment of casted struct value to property
- Date: Sat, 9 Jan 2021 19:44:05 +0000 (UTC)
commit 19e6752ccc1dda9c70c33ff059e6620b024c15af
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed Jan 6 12:19:10 2021 +0100
codegen: Fix assignment of casted struct value to property
Usage of address-of operator requires lvalue access. Therefore use a
temporary variable to be passed to property setter.
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1126
codegen/valaccodebasemodule.vala | 10 ++++
tests/Makefile.am | 1 +
tests/objects/property-real-struct-assignment.vala | 56 ++++++++++++++++++++++
3 files changed, 67 insertions(+)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 7ae6b47b0..dff36b296 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -6192,6 +6192,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
ccall.add_argument ((CCodeExpression) get_ccodenode (instance));
var cexpr = get_cvalue_ (value);
if (prop.property_type.is_real_non_null_struct_type ()) {
+ //TODO Make use of get_lvalue (value)
+ if (!(cexpr is CCodeConstant || cexpr is CCodeIdentifier)) {
+ var temp_value = store_temp_value (value, instance);
+ cexpr = get_cvalue_ (temp_value);
+ }
cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF,
cexpr);
}
ccall.add_argument (cexpr);
@@ -6248,6 +6253,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var cexpr = get_cvalue_ (value);
if (prop.property_type.is_real_non_null_struct_type ()) {
+ //TODO Make use of get_lvalue (value)
+ if (!(cexpr is CCodeConstant || cexpr is CCodeIdentifier)) {
+ var temp_value = store_temp_value (value, instance);
+ cexpr = get_cvalue_ (temp_value);
+ }
cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr);
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7645c42c7..eb6db5e26 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -462,6 +462,7 @@ TESTS = \
objects/property-delegate.vala \
objects/property-delegate-owned.vala \
objects/property-gboxed-nullable.vala \
+ objects/property-real-struct-assignment.vala \
objects/property-real-struct-no-accessor.test \
objects/property-simple-type-struct-nullable.vala \
objects/property-static.vala \
diff --git a/tests/objects/property-real-struct-assignment.vala
b/tests/objects/property-real-struct-assignment.vala
new file mode 100644
index 000000000..26790763c
--- /dev/null
+++ b/tests/objects/property-real-struct-assignment.vala
@@ -0,0 +1,56 @@
+struct Foo {
+ string s;
+}
+
+Foo? get_foo () {
+ return { "foo" };
+}
+
+class Manam : Object {
+ public virtual Foo faz { get; set; }
+}
+
+class Bar : Manam {
+ public Foo foo { get; set; }
+
+ public Bar () {
+ {
+ this.foo = get_foo ();
+ }
+ {
+ base.faz = get_foo ();
+ }
+ {
+ this.foo = (!) get_foo ();
+ }
+ {
+ base.faz = (!) get_foo ();
+ }
+ {
+ this.foo = (Foo) get_foo ();
+ }
+ {
+ base.faz = (Foo) get_foo ();
+ }
+ {
+ var f = get_foo ();
+ this.foo = (!) f;
+ }
+ {
+ var f = get_foo ();
+ base.faz = (!) f;
+ }
+ {
+ var f = get_foo ();
+ this.foo = (Foo) f;
+ }
+ {
+ var f = get_foo ();
+ base.faz = (Foo) f;
+ }
+ }
+}
+
+void main() {
+ var bar = new Bar ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]