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 2019/09/23 05:24:10 UTC

[groovy] branch GROOVY_2_4_X updated: GROOVY-8572: check for diamond without isUsingGenerics()

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_4_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_2_4_X by this push:
     new abdd042  GROOVY-8572: check for diamond without isUsingGenerics()
abdd042 is described below

commit abdd04242a62be120cbcc7f58b94be550c258686
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Sep 10 17:46:55 2019 -0500

    GROOVY-8572: check for diamond without isUsingGenerics()
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java       | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 595d310..2b2f6ab 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -928,16 +928,17 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
     protected void inferDiamondType(final ConstructorCallExpression cce, final ClassNode lType) {
         // check if constructor call expression makes use of the diamond operator
         ClassNode node = cce.getType();
-        if (node.isUsingGenerics() && node instanceof InnerClassNode && ((InnerClassNode) node).isAnonymous()) {
-            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()) {
+        if (cce.isUsingAnonymousInnerClass()) {
+            node = cce.getType().getUnresolvedSuperClass(false);
+            if (node == ClassHelper.OBJECT_TYPE)
+                node = cce.getType().getUnresolvedInterfaces(false)[0];
+            if (node.getGenericsTypes() != null && node.getGenericsTypes().length == 0) {
                 // InterfaceA<Foo> obj = new InterfaceA<>() { ... }
                 // InterfaceA<Foo> obj = new ClassA<>() { ... }
                 // ClassA<Foo> obj = new ClassA<>() { ... }
                 addStaticTypeError("Cannot use diamond <> with anonymous inner classes", cce);
             }
-        } else if (node.isUsingGenerics() && node.getGenericsTypes() != null && node.getGenericsTypes().length == 0) {
+        } else if (node.getGenericsTypes() != null && node.getGenericsTypes().length == 0) {
             ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
             if (argumentListExpression.getExpressions().isEmpty()) {
                 adjustGenerics(lType, node);