You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by cc...@apache.org on 2015/10/07 21:16:58 UTC
[5/5] incubator-groovy git commit: GROOVY-7618 Parameterless closure
to SAM Type argument coercion causes NPE during instruction selection (STC)
GROOVY-7618 Parameterless closure to SAM Type argument coercion causes NPE during instruction selection (STC)
Closes #135
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/baba6dfd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/baba6dfd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/baba6dfd
Branch: refs/heads/master
Commit: baba6dfdf46f3d8d7025ff319a875d4bcbdce80f
Parents: 50e422b
Author: Shil S <sh...@gmail.com>
Authored: Wed Oct 7 00:21:51 2015 -0400
Committer: Cedric Champeau <cc...@apache.org>
Committed: Wed Oct 7 21:15:47 2015 +0200
----------------------------------------------------------------------
.../transform/stc/StaticTypeCheckingVisitor.java | 5 ++++-
src/test/groovy/transform/stc/ClosuresSTCTest.groovy | 14 ++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/baba6dfd/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 1348fb8..c09e12b 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2365,7 +2365,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
ClassNode[] blockParameterTypes = (ClassNode[]) openBlock.getNodeMetaData(StaticTypesMarker.CLOSURE_ARGUMENTS);
if (blockParameterTypes==null) {
Parameter[] p = openBlock.getParameters();
- if (p.length==0 && parameterTypesForSAM.length!=0) {
+ if (p == null) {
+ // zero parameter closure e.g. { -> println 'no args' }
+ blockParameterTypes = ClassNode.EMPTY_ARRAY;
+ } else if (p.length==0 && parameterTypesForSAM.length!=0) {
// implicit it
blockParameterTypes = parameterTypesForSAM;
} else {
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/baba6dfd/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index fae7988..1eaeca8 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -500,5 +500,19 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
A.doSomething()
'''
}
+
+ void testParameterlessClosureToSAMTypeArgumentCoercion() {
+ assertScript '''
+ interface SamType {
+ int sam()
+ }
+
+ int foo(SamType samt) {
+ samt.sam()
+ }
+
+ assert foo { -> 1 } == 1
+ '''
+ }
}