[vala/staging] vala: Parameter following params-array paramete is not allowed
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Parameter following params-array paramete is not allowed
- Date: Wed, 26 May 2021 07:13:23 +0000 (UTC)
commit 7fc78574d382582806b8f28a1567d9e5ceac3bdf
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed May 26 09:02:52 2021 +0200
vala: Parameter following params-array paramete is not allowed
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1183
tests/Makefile.am | 1 +
tests/methods/params-array-preceding.test | 7 +++++++
vala/valamethod.vala | 6 ++++++
3 files changed, 14 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cfe4adbb4..3e754e58e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -229,6 +229,7 @@ TESTS = \
methods/nowrapper-no-vfunc.test \
methods/params-array.vala \
methods/params-array-abstract.test \
+ methods/params-array-preceding.test \
methods/params-array-with-throws.vala \
methods/print-attribute.vala \
methods/print-attribute-invalid.test \
diff --git a/tests/methods/params-array-preceding.test b/tests/methods/params-array-preceding.test
new file mode 100644
index 000000000..0e57bf188
--- /dev/null
+++ b/tests/methods/params-array-preceding.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+void foo (params string[] strv, int i) {
+}
+
+void main () {
+}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 427a37980..daef9789f 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -848,6 +848,7 @@ public class Vala.Method : Subroutine, Callable {
}
var optional_param = false;
+ var params_array_param = false;
foreach (Parameter param in parameters) {
if (!param.check (context)) {
error = true;
@@ -872,6 +873,11 @@ public class Vala.Method : Subroutine, Callable {
optional_param = true;
}
+ if (params_array_param) {
+ Report.error (param.source_reference, "parameter follows params-array
parameter");
+ } else if (param.params_array) {
+ params_array_param = true;
+ }
// Add local variable to provide access to params arrays which will be constructed
out of the given va-args
if (param.params_array && body != null) {
if (params_array_var != null) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]