[vala] Set array lengths for result variable
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Set array lengths for result variable
- Date: Fri, 5 Dec 2014 16:56:58 +0000 (UTC)
commit f403b05730a012563c75b56d7475d1e8240a7656
Author: Simon Werbeck <simon werbeck gmail com>
Date: Tue Nov 25 02:23:17 2014 +0100
Set array lengths for result variable
These where missing when generating postconditions
Fixes bug 737222
codegen/valaccodememberaccessmodule.vala | 5 +++++
tests/Makefile.am | 1 +
tests/methods/bug737222.vala | 13 +++++++++++++
3 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index afe8104..4f846b6 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -349,6 +349,11 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
} else {
result.cvalue = new CCodeIdentifier ("result");
}
+ if (array_type != null && !array_type.fixed_length && ((current_method != null &&
get_ccode_array_length (current_method)) || current_property_accessor != null)) {
+ for (int dim = 1; dim <= array_type.rank; dim++) {
+ result.append_array_length_cvalue (new CCodeUnaryExpression
(CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (get_array_length_cname ("result", dim))));
+ }
+ }
} else if (local.captured) {
// captured variables are stored on the heap
var block = (Block) local.parent_symbol;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0da5e3b..ee5bbfe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -65,6 +65,7 @@ TESTS = \
methods/bug723195.vala \
methods/bug726347.vala \
methods/bug736235.vala \
+ methods/bug737222.vala \
methods/generics.vala \
control-flow/break.vala \
control-flow/expressions-conditional.vala \
diff --git a/tests/methods/bug737222.vala b/tests/methods/bug737222.vala
new file mode 100644
index 0000000..85eee5a
--- /dev/null
+++ b/tests/methods/bug737222.vala
@@ -0,0 +1,13 @@
+int[] foo () ensures (result.length == 0 || result.length == 1) {
+ return new int[1];
+}
+
+[CCode (array_length = false, array_null_terminated = true)]
+string[] bar () ensures (result[0] == "bar") {
+ return new string[] {"bar"};
+}
+
+void main () {
+ foo ();
+ bar ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]