[
https://issues.apache.org/jira/browse/GROOVY-7506?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles resolved GROOVY-7506.
---------------------------------
Fix Version/s: 4.0.5
Resolution: Fixed
https://github.com/apache/groovy/commit/c341e2c44a64c25b8f8305dfe224cf795349c853
> Cannot assign value of type java.util.List<java.lang.String> to variable of
> type java.lang.String[]
> ---------------------------------------------------------------------------------------------------
>
> Key: GROOVY-7506
> URL: https://issues.apache.org/jira/browse/GROOVY-7506
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 2.4.3, 2.4.4
> Reporter: Mauro Molinari
> Assignee: Eric Milles
> Priority: Major
> Fix For: 4.0.5
>
>
> Usually the static type checker is smart enough to accept a {{List<String>}}
> to be assigned to a {{String[]}} variable, however in this particular case it
> is not:
> {code:title=Wrapper.java}
> package test;
> public class Wrapper {
> String[] wrapped;
>
> public Wrapper(String[] wrapped) {
> this.wrapped = wrapped;
> }
> }
> {code}
> {code:title=Other.java}
> package test;
> public class Other {
> private Wrapper foo;
>
> public void setFoo(String... args) {
> this.foo = new Wrapper(args);
> }
> }
> {code}
> {code:title=Test.groovy}
> package test
> import groovy.transform.CompileStatic
> @CompileStatic
> class Test {
>
> static test() {
> Other o = new Other()
> o.foo = ['foo', 'bar']
> }
> }
> {code}
> The assignment to {{o.foo}} unexpectedly fails. However, if I declare the
> {{foo}} field and {{setFoo}} method directly in {{Test}}, and change the code
> to assign to {{t.foo}} (where {{t}} is of type {{Test}}), the type checking
> passes.
> Please note that with Groovy 2.3.11 the assignment to {{o.foo}} was passing
> (no error produced by the static type checker!).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)