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

Eric Milles commented on GROOVY-9412:
-------------------------------------

I think the issue comes for Enum types because isUnsingGenerics() is true for 
the bound because the Enum class uses generics.

{code:java}
    private static boolean compareGenericsWithBound(final ClassNode classNode, 
final ClassNode bound) {
        if (classNode == null) {
            return false;
        }
        if (!bound.isUsingGenerics() || (classNode.getGenericsTypes() == null 
&& classNode.redirect().getGenericsTypes() != null)) {
            // if the bound is not using generics or the class node is a raw 
type, there's nothing to compare with
            return true;
        }
{code}

If this check in GenericsType found no generics in bound ("Bar" in this case), 
it would accept the match between "Foo" (classNode) and "Bar" (bound).

> enum added to List fails TypeChecked
> ------------------------------------
>
>                 Key: GROOVY-9412
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9412
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.0, 3.0.1
>         Environment: CentOS
>            Reporter: Ian
>            Priority: Major
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
>  
> {code:java}
> import groovy.transform.TypeChecked
> @TypeChecked
> class MyClass {
>     interface Foo {}
>     enum Bar implements Foo {
>         AA
>     }    
>     
>     void F() {
>         List<Foo> g = []
>         g.add(Bar.AA)
>     }
> }
> new MyClass()
> {code}
> Put this in a file "script.groovy" and call "groovy script.groovy"
> Expected: No output
>  Actual: 
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> <path to file>/Script.groovy: 14: [Static type checking] - Cannot call 
> java.util.List <Foo>#add(MyClass$Foo) with arguments [MyClass$Bar] 
>  @ line 14, column 9.
>            g.add(Bar.AA)
>            ^
> 1 error{noformat}
> Does not occur in 3.0.0-rc-3 or earlier.
> Looks similar to GROOVY-8960 but does not occur in 2.5.5
> Workaround: Add cast "g.add(Bar.AA as Foo)"



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to