[vala/staging] vala: Async methods don't allow out-parameters before in-parameters



commit 15141e3f25aa57cd67cc9cc7734e2be46729b0ea
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Oct 21 10:34:28 2018 +0200

    vala: Async methods don't allow out-parameters before in-parameters
    
    out-parameters are always handled in the *_finish implementation and
    therefore are asynchronous.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/636

 tests/Makefile.am                             |  1 +
 tests/asynchronous/out-parameter-invalid.test |  7 +++++++
 vala/valamethod.vala                          | 14 ++++++++++++++
 3 files changed, 22 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0f0c8f007..96b6a3196 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -381,6 +381,7 @@ TESTS = \
        asynchronous/bug793158.vala \
        asynchronous/closures.vala \
        asynchronous/generator.vala \
+       asynchronous/out-parameter-invalid.test \
        asynchronous/yield.vala \
        generics/bug640330.test \
        generics/bug640330.vala \
diff --git a/tests/asynchronous/out-parameter-invalid.test b/tests/asynchronous/out-parameter-invalid.test
new file mode 100644
index 000000000..070218315
--- /dev/null
+++ b/tests/asynchronous/out-parameter-invalid.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+async void foo (out int i, int j) {
+}
+
+void main () {
+}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 1db46ae45..719db4f24 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -746,6 +746,20 @@ public class Vala.Method : Subroutine, Callable {
                        }
                }
 
+               if (coroutine) {
+                       // async methods don't allow out-parameters before in-parameters
+                       bool requires_attribute = false;
+                       for (int i = parameters.size - 1; i >= 0; i--) {
+                               var param = parameters[i];
+                               if (param.direction == ParameterDirection.IN) {
+                                       requires_attribute = true;
+                               } else if (requires_attribute) {
+                                       error = true;
+                                       Report.error (param.source_reference, "Output parameters are not 
allowed before input parameters in async methods");
+                               }
+                       }
+               }
+
                foreach (DataType error_type in get_error_types ()) {
                        error_type.check (context);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]