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

Saravanan commented on GROOVY-11616:
------------------------------------

This code fails with the snapshot 20250515.174741-1495. I am not sure if this 
change got checked in before or after that snapshot was generated.

I am compiling this with @CompileStatic and I am not assigning it to any 
variables/returning etc.
{code:java}
Arrays.asList(
     new ArrayList<String>(), 
     new ArrayList<Long>(),
     new ArrayList<Double>()
);
{code}
The error I see is


{noformat}
 Cannot call <T> java.util.Arrays#asList(T[]) with arguments 
[java.util.ArrayList<java.lang.String>, java.util.ArrayList<java.lang.Long>, 
java.util.ArrayList<java.lang.Double>]
 @ line 84, column 9.
           Arrays.asList(new ArrayList<String>(), new ArrayList<Long>(), new 
ArrayList<Double>());
           ^{noformat}

> Functions that take var args will default the type of the first argument, 
> java tries to find the common parent type from all arguments
> --------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11616
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11616
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 4.0.24, 5.0.0-alpha-12
>            Reporter: Saravanan
>            Assignee: Eric Milles
>            Priority: Minor
>             Fix For: 5.0.0-beta-1
>
>
>  
> {code:java}
> public class Interfaces {
>     class Blah {
>     }
>     class BlahBlah extends Blah {
>     }
>     class BlahBlahBlah extends Blah {
>     }
>     public String myThing() {
>         // This fails with
>         //     Incompatible generic argument types. Cannot assign 
> java.util.List<? extends com.org.interfaces.Interfaces.Blah>
>         //     to: java.util.List<com.org.interfaces.Interfaces.Blah>
>         // To fix change to explicitly define generic type
>         //      Arrays.<Blah> asList(...)
>         List<Blah> myArray = Arrays.asList(new Blah(), new BlahBlah(), new 
> BlahBlahBlah(), new Blah());
>     }
> }
> {code}
> Arrays.asList takes a vararg parameter. Groovy defaults to assuming that the 
> first parameter type is the type (or parent type) for all parameters that 
> follow. If we use instances of multiple derived types, Groovy errors out 
> without trying to find the common parent type



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to