]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't tweak closure on static lambdas
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 21 Jan 2019 16:31:07 +0000 (17:31 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 21 Jan 2019 16:31:07 +0000 (17:31 +0100)
Regression of 92ba4e178723b1aa6404da556c79b08abe5eaf05

Fixes https://gitlab.gnome.org/GNOME/vala/issues/740

tests/Makefile.am
tests/delegates/lambda-mixed-instance-static.vala [new file with mode: 0644]
vala/valamethodcall.vala

index c1f971b8749ab4e2286c10cdffeefda62efae14d..a60f77f88c18972f3609749a4b3562089d25f7d9 100644 (file)
@@ -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 (file)
index 0000000..f25d08a
--- /dev/null
@@ -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; }
+       );
+}
index e9cfc1c9ddaae1237ddd5e391bc009b21201ee70..56b73648cef38288030866cfda8f129fbbbfdbc8 100644 (file)
@@ -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;
                                }
                        }
                }