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 2017/09/14 10:18:55 UTC

[1/2] groovy git commit: GROOVY-8247: AIOOBE in StaticTypeCheckingVisitor with SAM and explicit closure parameter (closes #600)

Repository: groovy
Updated Branches:
  refs/heads/master 5cdfa18f0 -> a2eb41e34


GROOVY-8247: AIOOBE in StaticTypeCheckingVisitor with SAM and explicit closure parameter (closes #600)


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

Branch: refs/heads/master
Commit: d02a2ddf017e2475d3c8ba2e4d5289952072a8d1
Parents: 5cdfa18
Author: paulk <pa...@asert.com.au>
Authored: Thu Sep 14 19:38:17 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Sep 14 20:14:57 2017 +1000

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          | 12 ++++---
 .../groovy/transform/stc/Groovy8247Bug.groovy   | 36 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d02a2ddf/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 7e38ac4..98aebd7 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2419,20 +2419,24 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                 blockParameterTypes = extractTypesFromParameters(p);
             }
         }
-        for (int i=0; i<blockParameterTypes.length; i++) { //TODO: equal length guaranteed?
-            extractGenericsConnections(SAMTypeConnections, blockParameterTypes[i], parameterTypesForSAM[i]);
+        for (int i=0; i<blockParameterTypes.length; i++) {
+            extractGenericsConnections(SAMTypeConnections, blockParameterTypes[i], typeOrNull(parameterTypesForSAM, i));
         }
 
         // and finally we apply the generics information to the parameters and
         // store the type of parameter and block type as meta information
-        for (int i=0; i<blockParameterTypes.length; i++) { //TODO: equal length guaranteed?
+        for (int i=0; i<blockParameterTypes.length; i++) {
             ClassNode resolvedParameter =
-                    applyGenericsContext(SAMTypeConnections, parameterTypesForSAM[i]);
+                    applyGenericsContext(SAMTypeConnections, typeOrNull(parameterTypesForSAM, i));
             blockParameterTypes[i] = resolvedParameter;
         }
         openBlock.putNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS, blockParameterTypes);
     }
 
+    private ClassNode typeOrNull(ClassNode[] parameterTypesForSAM, int i) {
+        return i < parameterTypesForSAM.length ? parameterTypesForSAM[i] : null;
+    }
+
     private List<ClassNode[]> getSignaturesFromHint(final ClosureExpression expression, final MethodNode selectedMethod, final Expression hintClass, final Expression options) {
         // initialize hints
         List<ClassNode[]> closureSignatures;

http://git-wip-us.apache.org/repos/asf/groovy/blob/d02a2ddf/src/test/groovy/transform/stc/Groovy8247Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/Groovy8247Bug.groovy b/src/test/groovy/transform/stc/Groovy8247Bug.groovy
new file mode 100644
index 0000000..7488352
--- /dev/null
+++ b/src/test/groovy/transform/stc/Groovy8247Bug.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.transform.stc
+
+class Groovy8247Bug extends StaticTypeCheckingTestCase {
+    void testClosureWithExplicitParamNoInferrableArguments() {
+        assertScript '''
+            def runnable(Runnable r) {
+                r.run()
+            }
+            def foo() {
+                runnable { it -> // note explicit it
+                    println it
+                }
+            }
+            foo()
+        '''
+    }
+}


[2/2] groovy git commit: GROOVY-8246: AIOOBE in StaticTypeCheckingVisitor with SAM (closes #601)

Posted by pa...@apache.org.
GROOVY-8246: AIOOBE in StaticTypeCheckingVisitor with SAM (closes #601)


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

Branch: refs/heads/master
Commit: a2eb41e34c81ea806e471186dbc8c612835e32e8
Parents: d02a2dd
Author: paulk <pa...@asert.com.au>
Authored: Thu Sep 14 19:41:00 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Sep 14 20:17:38 2017 +1000

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingVisitor.java          |  2 +-
 .../groovy/transform/stc/Groovy8246Bug.groovy   | 36 ++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a2eb41e3/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 98aebd7..a257aa0 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4021,7 +4021,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                 ClassNode[] closureParamTypes = (ClassNode[])(enclosingClosure!=null?enclosingClosure.getClosureExpression().getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS):null);
                 if (type==null && enclosingClosure !=null && "it".equals(variable.getName()) && closureParamTypes!=null) {
                     final Parameter[] parameters = enclosingClosure.getClosureExpression().getParameters();
-                    if (parameters.length==0 && getTemporaryTypesForExpression(vexp)==null) {
+                    if (parameters.length==0 && getTemporaryTypesForExpression(vexp)==null && closureParamTypes.length!=0) {
                         type = closureParamTypes[0];
                     }
                 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/a2eb41e3/src/test/groovy/transform/stc/Groovy8246Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/Groovy8246Bug.groovy b/src/test/groovy/transform/stc/Groovy8246Bug.groovy
new file mode 100644
index 0000000..e634a76
--- /dev/null
+++ b/src/test/groovy/transform/stc/Groovy8246Bug.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.transform.stc
+
+class Groovy8246Bug extends StaticTypeCheckingTestCase {
+    void testClosureWithImplicitParamNoInferrableArguments() {
+        assertScript '''
+            def runnable(Runnable r) {
+                r.run()
+            }
+            def foo() {
+                runnable {
+                    println it
+                }
+            }
+            foo()
+        '''
+    }
+}