[vala] Set lvalue access for struct properties
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Set lvalue access for struct properties
- Date: Fri, 2 Sep 2011 11:00:57 +0000 (UTC)
commit f9186d12f28911d98e6f41d58f595fa81de602cb
Author: Luca Bruno <lucabru src gnome org>
Date: Fri Sep 2 12:57:30 2011 +0200
Set lvalue access for struct properties
Fixes bug 658046.
codegen/valaccodememberaccessmodule.vala | 4 ++++
tests/Makefile.am | 1 +
tests/objects/bug658046.vala | 17 +++++++++++++++++
vala/valamemberaccess.vala | 2 +-
4 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 349a96e..deef89c 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -193,6 +193,10 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
CCodeExpression inst;
inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
set_cvalue (expr, new CCodeMemberAccess.pointer (inst, get_ccode_name (prop.field)));
+ if (expr.lvalue) {
+ // no temp variable
+ return;
+ }
} else if (!get_ccode_no_accessor_method (prop)) {
var base_property = prop;
if (prop.base_property != null) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d1b1491..25004ec 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -109,6 +109,7 @@ TESTS = \
objects/bug646792.vala \
objects/bug653138.vala \
objects/bug654702.vala \
+ objects/bug658046.vala \
errors/errors.vala \
errors/bug567181.vala \
errors/bug579101.vala \
diff --git a/tests/objects/bug658046.vala b/tests/objects/bug658046.vala
new file mode 100644
index 0000000..263246b
--- /dev/null
+++ b/tests/objects/bug658046.vala
@@ -0,0 +1,17 @@
+struct Foo {
+ int i;
+}
+
+class Bar {
+ public Foo prop { get; protected set; }
+
+ public void baz () {
+ prop.i = 10;
+ }
+}
+
+void main () {
+ var bar = new Bar ();
+ bar.baz ();
+ assert (bar.prop.i == 10);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 1ec08da..9ced173 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -829,7 +829,7 @@ public class Vala.MemberAccess : Expression {
instance = symbol_reference is Property && ((Property) symbol_reference).binding == MemberBinding.INSTANCE;
}
var this_access = inner.symbol_reference is Parameter && inner.symbol_reference.name == "this";
- if (instance && inner.value_type is StructValueType && !inner.value_type.nullable && (symbol_reference is Method || lvalue) && ((inner is MemberAccess && inner.symbol_reference is Variable) || inner is ElementAccess) && !this_access) {
+ if (instance && inner.value_type is StructValueType && !inner.value_type.nullable && (symbol_reference is Method || lvalue) && ((inner is MemberAccess && (inner.symbol_reference is Variable || inner.symbol_reference is Property)) || inner is ElementAccess) && !this_access) {
inner.lvalue = true;
if (inner is MemberAccess) {
((MemberAccess) inner).check_lvalue_struct_access ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]