[vala/staging] vala: Don't tweak closure on static lambdas



commit 8b27678dbbc4810b1bf15f5cdbe7a63d22b26ad0
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Jan 21 17:31:07 2019 +0100

    vala: Don't tweak closure on static lambdas
    
    Regression of 92ba4e178723b1aa6404da556c79b08abe5eaf05
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/740

 tests/Makefile.am                                 |  1 +
 tests/delegates/lambda-mixed-instance-static.vala | 18 ++++++++++++++++++
 vala/valamethodcall.vala                          |  5 +++--
 3 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c1f971b87..a60f77f88 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -239,6 +239,7 @@ TESTS = \
        delegates/fields.vala \
        delegates/fields-no-target.vala \
        delegates/instance-method-to-no-target.test \
+       delegates/lambda-mixed-instance-static.vala \
        delegates/lambda-shared-closure.vala \
        delegates/reference_transfer.vala \
        delegates/wrapper.vala \
diff --git a/tests/delegates/lambda-mixed-instance-static.vala 
b/tests/delegates/lambda-mixed-instance-static.vala
new file mode 100644
index 000000000..f25d08a18
--- /dev/null
+++ b/tests/delegates/lambda-mixed-instance-static.vala
@@ -0,0 +1,18 @@
+[CCode (has_target = false)]
+delegate int FooFunc (int i);
+
+delegate int BarFunc (int i);
+
+void func (FooFunc f, BarFunc b) {
+       assert (f (42) == 42);
+       assert (b (23) == 4711);
+}
+
+void main () {
+       int global = 4711;
+
+       func (
+               (i) => { assert (i == 42); return i; },
+               (i) => { assert (i == 23); return global; }
+       );
+}
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index e9cfc1c9d..56b73648c 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -488,8 +488,9 @@ public class Vala.MethodCall : Expression {
                // TODO https://gitlab.gnome.org/GNOME/vala/issues/59
                if (force_lambda_method_closure) {
                        foreach (Expression arg in get_argument_list ()) {
-                               if (arg is LambdaExpression) {
-                                       ((LambdaExpression) arg).method.closure = true;
+                               unowned LambdaExpression? lambda = arg as LambdaExpression;
+                               if (lambda != null && lambda.method.binding != MemberBinding.STATIC) {
+                                       lambda.method.closure = true;
                                }
                        }
                }


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