[ 
https://issues.apache.org/jira/browse/GROOVY-12297?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Björn Kautler reopened GROOVY-12297:
------------------------------------

Ah, but a typed Tuple or List should imho work if possible like
{code}
@groovy.transform.CompileStatic
class Foo {
  def foo() {
    def (String foo, String bar) = bar()
    println(foo)
    println(bar)
  }

  List<String> bar() {
    ["foo", "bar"]
  }
}
new Foo().foo()
{code}
or
{code}
@groovy.transform.CompileStatic
class Foo {
  def foo() {
    def (String foo, String bar) = bar()
    println(foo)
    println(bar)
  }

  Tuple<String> bar() {
    ["foo", "bar"] as Tuple2
  }
}
new Foo().foo()
{code}

> STC: multi-assignment works with Tuple-returning methods on the RHS but not 
> with List-returning methods
> -------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12297
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12297
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.0.3
>            Reporter: Björn Kautler
>            Priority: Major
>
> This does work under STC:
> {code}
> @groovy.transform.CompileStatic
> class Foo {
>   def foo() {
>     def (foo, bar) = bar()
>     println(foo)
>     println(bar)
>   }
>   Tuple2 bar() {
>     ["foo", "bar"] as Tuple2
>   }
> }
> new Foo().foo()
> {code}
> but this does cause a compilation error that only List or Tuple on the RHS 
> are supported:
> {code}
> @groovy.transform.CompileStatic
> class Foo {
>   def foo() {
>     def (foo, bar) = bar()
>     println(foo)
>     println(bar)
>   }
>   List bar() {
>     ["foo", "bar"]
>   }
> }
> new Foo().foo()
> {code}
> Would be nice if also {{List}} would work here.



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

Reply via email to