[vala] Fix calling methods on struct pointers
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix calling methods on struct pointers
- Date: Sat, 25 Jan 2014 14:34:36 +0000 (UTC)
commit 95d0aa0246edbbeade95afaa569243841507bd07
Author: Luca Bruno <lucabru src gnome org>
Date: Sat Jan 25 14:57:18 2014 +0100
Fix calling methods on struct pointers
Fixes bug 686190
codegen/valaccodebasemodule.vala | 1 +
tests/Makefile.am | 1 +
tests/structs/bug686190.vala | 14 ++++++++++++++
vala/valamemberaccess.vala | 13 ++++++++++---
4 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 488d434..a48df49 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5121,6 +5121,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public override void visit_pointer_indirection (PointerIndirection expr) {
set_cvalue (expr, new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION,
get_cvalue (expr.inner)));
+ ((GLibValue) expr.target_value).lvalue = get_lvalue (expr.inner.target_value);
}
public override void visit_addressof_expression (AddressofExpression expr) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 141b048..85a9213 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -94,6 +94,7 @@ TESTS = \
structs/bug667890.vala \
structs/bug669580.vala \
structs/bug685177.vala \
+ structs/bug686190.vala \
structs/bug690380.vala \
delegates/delegates.vala \
delegates/bug539166.vala \
diff --git a/tests/structs/bug686190.vala b/tests/structs/bug686190.vala
new file mode 100644
index 0000000..4d26975
--- /dev/null
+++ b/tests/structs/bug686190.vala
@@ -0,0 +1,14 @@
+struct Foo {
+ int x;
+
+ public void meth () {
+ x = 10;
+ }
+}
+
+void main () {
+ Foo foo = Foo ();
+ Foo* bar = &foo;
+ bar.meth ();
+ assert (foo.x == 10);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index af9f51f..b0c48ee 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -891,10 +891,17 @@ public class Vala.MemberAccess : Expression {
var this_access = inner.symbol_reference is Parameter && inner.symbol_reference.name ==
"this";
var struct_or_array = (inner.value_type is StructValueType && !inner.value_type.nullable) ||
inner.value_type is ArrayType;
- if (instance && struct_or_array && (symbol_reference is Method || lvalue) && ((inner is
MemberAccess && inner.symbol_reference is Variable) || inner is ElementAccess) && !this_access) {
+ var ma = inner as MemberAccess;
+ if (ma == null && struct_or_array && inner is PointerIndirection) {
+ // (*struct)->method()
+ ma = ((PointerIndirection) inner).inner as MemberAccess;
+ }
+
+ if (instance && struct_or_array && (symbol_reference is Method || lvalue) && ((ma != null &&
ma.symbol_reference is Variable) || inner is ElementAccess) && !this_access) {
inner.lvalue = true;
- if (inner is MemberAccess) {
- ((MemberAccess) inner).check_lvalue_access ();
+ if (ma != null) {
+ ma.lvalue = true;
+ ma.check_lvalue_access ();
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]