You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2019/09/10 21:21:00 UTC

[jira] [Commented] (GROOVY-8572) Groovy 2.4.12 Static compiler fails on nonsense type inference error

    [ https://issues.apache.org/jira/browse/GROOVY-8572?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16926897#comment-16926897 ] 

Eric Milles commented on GROOVY-8572:
-------------------------------------

Still a problem in 2.4.17.  StaticTypeCheckingVisitor is going into this block to generate the error:
{code:java}
    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()) {
                // InterfaceA<Foo> obj = new InterfaceA<>() { ... }
                // InterfaceA<Foo> obj = new ClassA<>() { ... }
                // ClassA<Foo> obj = new ClassA<>() { ... }
                addStaticTypeError("Cannot use diamond <> with anonymous inner classes", cce);
            }
        }
{code}

It goes there because ResolveVisitor is setting usingGenerics to true in resolveGenericsTypes and supporting methods.  I'm not sure why ResolveVisitor is setting this flag for the anon. inner when the type being resolved is {{Map<String,Object>}} or {{List<String>}}, which are types used within the anon. inner class body.

> Groovy 2.4.12 Static compiler fails on nonsense type inference error
> --------------------------------------------------------------------
>
>                 Key: GROOVY-8572
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8572
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.4.12
>            Reporter: Martin Skurla
>            Priority: Major
>
> I am using Gradle which internally currently uses Groovy 2.4.12.
> I am getting the following error:
> {code:java}
> martin@martin-desktop:~/devel/apollo/buildteam/gradle_plugins(master)$ ./gradlew clean test
> > Task :compileGroovy
> startup failed:
> /home/martin/devel/apollo/buildteam/gradle_plugins/src/main/groovy/apollosoft/build/support/gradle/assets/ApolloAssetsDSLExtension.groovy: 54: [Static type checking] - Cannot use diamond <> with anonymous inner classes
>  @ line 54, column 28.
>            closure.delegate = new Object() {
>                               ^
> 1 error
> {code}
> It looks like it is wrong, I am not specifying any diamond operator anywhere.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)