You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/10/03 12:20:33 UTC

groovy git commit: GROOVY-8816: NPE in inferClosureParameterTypes with CompileStatic and incorrect zero-arg closure

Repository: groovy
Updated Branches:
  refs/heads/master f33a378c1 -> ddfac0eff


GROOVY-8816: NPE in inferClosureParameterTypes with CompileStatic and incorrect zero-arg closure


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

Branch: refs/heads/master
Commit: ddfac0effa144551c1abee73b1d04a8507a09880
Parents: f33a378
Author: Paul King <pa...@asert.com.au>
Authored: Wed Oct 3 22:20:07 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Wed Oct 3 22:20:27 2018 +1000

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          |  1 +
 src/test/groovy/bugs/Groovy8816Bug.groovy       | 36 ++++++++++++++++++++
 2 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/ddfac0ef/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 2f48985..3e6d945 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2780,6 +2780,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
             // In practice, it could be done differently but it has the main advantage of reusing
             // existing code, hence reducing the amount of code to debug in case of failure.
             ClassNode[] inferred = resolveGenericsFromTypeHint(receiver, arguments, selectedMethod, signature);
+            if (closureParams == null) return; // no-arg closure
             if (signature.length == closureParams.length // same number of arguments
                     || (signature.length == 1 && closureParams.length == 0) // implicit it
                     || (closureParams.length > signature.length && inferred[inferred.length - 1].isArray())) { // vargs

http://git-wip-us.apache.org/repos/asf/groovy/blob/ddfac0ef/src/test/groovy/bugs/Groovy8816Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8816Bug.groovy b/src/test/groovy/bugs/Groovy8816Bug.groovy
new file mode 100644
index 0000000..880a02e
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8816Bug.groovy
@@ -0,0 +1,36 @@
+/*
+ *  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 Groovy8816Bug extends GroovyTestCase {
+    void testCallNoArgClosureWithArg() {
+        def msg = shouldFail MissingMethodException, '''
+        import groovy.transform.CompileStatic
+
+        @CompileStatic
+        void main() {
+            [0].each { -> }
+        }
+
+        main()
+        '''
+        assert msg.contains('No signature of method:')
+        assert msg.contains('doCall() is applicable for argument types: (Integer) values: [0]')
+    }
+}