Repository: incubator-groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 015be1a6e -> e956d2d0b


GROOVY-7159: STC claims non-existent Diamond in Anonymous Inner Class with 
Generics

Closes #1


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

Branch: refs/heads/GROOVY_2_4_X
Commit: e956d2d0b88b2ea3883c0ca370b86c235c80cd5a
Parents: 015be1a
Author: Shil S <shil.si...@gmail.com>
Authored: Sat Apr 18 23:57:13 2015 -0400
Committer: Cedric Champeau <cchamp...@apache.org>
Committed: Thu May 7 22:49:55 2015 +0200

----------------------------------------------------------------------
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java  |  3 ++-
 .../transform/stc/AnonymousInnerClassSTCTest.groovy      | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e956d2d0/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 3838ab2..f856da4 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -771,7 +771,8 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
         // check if constructor call expression makes use of the diamond 
operator
         ClassNode node = cce.getType();
         if (node.isUsingGenerics() && node instanceof InnerClassNode && 
((InnerClassNode) node).isAnonymous()) {
-            node = node.getUnresolvedSuperClass(false);
+            ClassNode[] interfaces = node.getInterfaces();
+            node = interfaces != null && interfaces.length == 1 ? 
interfaces[0] : node.getUnresolvedSuperClass(false);
             if ((node.getGenericsTypes() == null || 
node.getGenericsTypes().length == 0) && lType.isUsingGenerics()) {
                 // InterfaceA<Foo> obj = new InterfaceA<>() { ... }
                 // InterfaceA<Foo> obj = new ClassA<>() { ... }

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e956d2d0/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy 
b/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy
index d12faee..6a4a0a3 100644
--- a/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy
+++ b/src/test/groovy/transform/stc/AnonymousInnerClassSTCTest.groovy
@@ -170,4 +170,15 @@ class AnonymousInnerClassSTCTest extends 
StaticTypeCheckingTestCase {
             assert a.foo() == "pm"
         '''
     }
+
+    void testAICWithGenerics() {
+        assertScript '''
+            Comparator<Integer> comp = new Comparator<Integer>(){
+                @Override
+                int compare(Integer o1, Integer o2) {
+                    return 0
+                }
+            }
+        '''
+    }
 }

Reply via email to