Repository: incubator-groovy
Updated Branches:
  refs/heads/master 0f645889a -> 5371c10ad


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/5371c10a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/5371c10a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/5371c10a

Branch: refs/heads/master
Commit: 5371c10adb036febd1ed9a7f2208ddb68e4ad0b8
Parents: 0f64588
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:48:37 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/5371c10a/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 c1929c9..e4b3ed7 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/5371c10a/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