[vala] Fix regression when calling .resize() or .move() on arrays inside structs
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix regression when calling .resize() or .move() on arrays inside structs
- Date: Thu, 29 Sep 2011 09:18:04 +0000 (UTC)
commit a786191f5192a3406dae0117e65593a565004348
Author: Luca Bruno <lucabru src gnome org>
Date: Thu Sep 29 10:52:06 2011 +0200
Fix regression when calling .resize() or .move() on arrays inside structs
The check for lvalue access has been extended to arrays for simplifying
the conditions.
Fixes bug 660426.
tests/Makefile.am | 1 +
tests/structs/bug660426.vala | 9 +++++++++
vala/valaelementaccess.vala | 4 ++--
vala/valamemberaccess.vala | 14 +++++++-------
4 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 098f646..303be72 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -75,6 +75,7 @@ TESTS = \
structs/bug654753.vala \
structs/bug656693.vala \
structs/bug658048.vala \
+ structs/bug660426.vala \
delegates/delegates.vala \
delegates/bug539166.vala \
delegates/bug595610.vala \
diff --git a/tests/structs/bug660426.vala b/tests/structs/bug660426.vala
new file mode 100644
index 0000000..c78e6ed
--- /dev/null
+++ b/tests/structs/bug660426.vala
@@ -0,0 +1,9 @@
+struct Foo {
+ int[] bar;
+}
+
+void main () {
+ var f = Foo ();
+ f.bar.resize (10);
+ assert (f.bar.length == 10);
+}
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 70a46a8..58f0e4d 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -146,13 +146,13 @@ public class Vala.ElementAccess : Expression {
if (context.profile == Profile.GOBJECT && ma != null && ma.symbol_reference is ArrayLengthField) {
// propagate lvalue for gobject length access
ma.inner.lvalue = true;
- ((MemberAccess) ma.inner).check_lvalue_struct_access ();
+ ((MemberAccess) ma.inner).check_lvalue_access ();
} else if (ma != null && ma.symbol_reference is Field &&
ma.inner != null && ma.inner.symbol_reference is Variable &&
ma.inner.value_type is StructValueType && !ma.inner.value_type.nullable) {
// propagate lvalue if container is a field and container.inner is a struct variable
ma.lvalue = true;
- ma.check_lvalue_struct_access ();
+ ma.check_lvalue_access ();
}
}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 5968e68..64d2b51 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -752,11 +752,8 @@ public class Vala.MemberAccess : Expression {
inner.value_type = this_parameter.variable_type.copy ();
inner.value_type.value_owned = false;
inner.symbol_reference = this_parameter;
- } else if (context.profile == Profile.GOBJECT && lvalue && member is ArrayLengthField) {
- inner.lvalue = true;
- ((MemberAccess) inner).check_lvalue_struct_access ();
} else {
- check_lvalue_struct_access ();
+ check_lvalue_access ();
}
if (context.experimental_non_null && instance && inner.value_type.nullable &&
@@ -817,7 +814,7 @@ public class Vala.MemberAccess : Expression {
return !error;
}
- public void check_lvalue_struct_access () {
+ public void check_lvalue_access () {
if (inner == null) {
return;
}
@@ -828,11 +825,14 @@ public class Vala.MemberAccess : Expression {
if (!instance) {
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) {
+ var struct_or_array = (inner.value_type is StructValueType && !inner.value_type.nullable) || (CodeContext.get ().profile == Profile.GOBJECT && 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) {
inner.lvalue = true;
if (inner is MemberAccess) {
- ((MemberAccess) inner).check_lvalue_struct_access ();
+ ((MemberAccess) inner).check_lvalue_access ();
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]