You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2017/08/12 16:35:55 UTC

groovy git commit: GROOVY-7995: @CS short syntax closure call from closure (closes #576, closes #460)

Repository: groovy
Updated Branches:
  refs/heads/master c46209e14 -> 9e21d7566


GROOVY-7995: @CS short syntax closure call from closure (closes #576, closes #460)

Short syntax of closure call invokes wrong closure if wrapped in another
closure. This fix includes a combination of the contributed commit from
PR #460 along with the patch (see PR comments) provided by Jochen.

Thanks to @blindpirate for the contribution.


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9e21d756
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9e21d756
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9e21d756

Branch: refs/heads/master
Commit: 9e21d756628198fe82c86bfb21a4b02618d7253b
Parents: c46209e
Author: John Wagenleitner <jw...@apache.org>
Authored: Sat Jul 22 10:06:21 2017 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Sat Aug 12 09:32:15 2017 -0700

----------------------------------------------------------------------
 .../MethodCallExpressionTransformer.java        |  8 +++-
 src/test/groovy/bugs/Groovy7995Bug.groovy       | 41 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9e21d756/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java b/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
index 2833483..c93db9e 100644
--- a/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
+++ b/src/main/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java
@@ -75,6 +75,7 @@ public class MethodCallExpressionTransformer {
                 result.setSafe(expr.isSafe());
                 result.setSpreadSafe(expr.isSpreadSafe());
                 result.setMethodTarget(StaticTypeCheckingVisitor.CLOSURE_CALL_VARGS);
+                result.copyNodeMetaData(expr);
                 return result;
             }
         }
@@ -159,9 +160,12 @@ public class MethodCallExpressionTransformer {
     }
 
     private static boolean isCallOnClosure(final MethodCallExpression expr) {
+        MethodNode target = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
         return expr.isImplicitThis()
-                && expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET) == StaticTypeCheckingVisitor.CLOSURE_CALL_VARGS
-                && !"call".equals(expr.getMethodAsString());
+                && !"call".equals(expr.getMethodAsString())
+                && (target == StaticTypeCheckingVisitor.CLOSURE_CALL_VARGS
+                    || target == StaticTypeCheckingVisitor.CLOSURE_CALL_NO_ARG
+                    || target == StaticTypeCheckingVisitor.CLOSURE_CALL_ONE_ARG);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/9e21d756/src/test/groovy/bugs/Groovy7995Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7995Bug.groovy b/src/test/groovy/bugs/Groovy7995Bug.groovy
new file mode 100644
index 0000000..d3856fb
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy7995Bug.groovy
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+class Groovy7995Bug extends GroovyTestCase{
+
+    void testClosureShortSyntaxCallFromOtherClosure(){
+        assertScript('''
+            @groovy.transform.CompileStatic
+            class Foo {
+                Closure c = { 'ok' }
+                Closure wrap = {
+                    c()
+                }
+            
+                def run() {
+                    wrap()
+                }
+            }
+            
+            assert new Foo().run()=='ok'
+        ''')
+    }
+
+}