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

Eric Milles edited comment on GROOVY-11060 at 5/17/23 3:37 PM:
---------------------------------------------------------------

What’s clunky? The plus sequence? The spread into list in the example creates a 
list. Then you as into an array. -Now that I look at it, you should be able to 
just use *A as your argument expression.-
{code:groovy}
@CompileStatic
class Groovy11060 {
  public static final List<String> A_LIST = ['a1', 'a2']

  static void varargs(String... strings) {
    println Arrays.toString(strings)
  }

  static main(args) {
    varargs(*A_LIST) // GROOVY-10597
    varargs(A_LIST as String[])
    varargs(A_LIST.toArray(new String[0]))
  }
}
{code}


was (Author: emilles):
What’s clunky? The plus sequence? The spread into list in the example creates a 
list. Then you as into an array. -Now that I look at it, you should be able to 
just use *A as your argument expression.-
{code:groovy}
@CompileStatic
class Groovy11060 {
  public static final List<String> A_LIST = ['a1', 'a2']

  static void varargs(String... strings) {
    println Arrays.toString(strings)
  }

  static main(args) {
    varargs(*A_LIST) // error -- could be fixed for Iterable<String> to 
String...
    varargs(A_LIST as String[])
    varargs(A_LIST.toArray(new String[0]))
  }
}
{code}

> SC internal error when spreading inside list literal
> ----------------------------------------------------
>
>                 Key: GROOVY-11060
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11060
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 4.0.12
>            Reporter: Christopher Smith
>            Priority: Major
>
> Spreading a list inside brackets causes a {{SpreadExpression should not be 
> visited here}} during class generation. (The business instance of this is 
> trying to use a list of URL patterns for Spring {{antMatchers}}.)
> {code}
> @CompileStatic
> class Bug {
>     public static final List<String> A = ['a1', 'a2']
>     static void varargs(String... strings) {
>         println Arrays.toString(strings)
>     }
>     public static void main(String... args) {
>         varargs([
>             *A
>         ] as String[])
>     }
> }
> {code}



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

Reply via email to