[jira] [Commented] (GROOVY-8194) property access on a list acts like the spread operator

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[jira] [Commented] (GROOVY-8194) property access on a list acts like the spread operator

JIRA jira@apache.org

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

Paul King commented on GROOVY-8194:
-----------------------------------

What Jochen said. This is a long advertised feature of the language since 1.0. If the list doesn't have the property, i.e. would throw MPE, then the property access is auto spread across the list.

> property access on a list acts like the spread operator
> -------------------------------------------------------
>
>                 Key: GROOVY-8194
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8194
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.4, 2.4.10
>            Reporter: zyro
>
> why does the following assertion pass?
> {code}
> class Dummy {
>     String name
> }
> def dummyOne = new Dummy(name: "dummy one")
> def dummyTwo = new Dummy(name: "dummy two")
> def dummies = [dummyOne, dummyTwo]
> assert dummies.name == ["dummy one", "dummy two"]
> {code}
> imho, {{dummies.name}} should fail with a {{MissingPropertyException}}.
> the assertion should only pass if the spread operator is actually used like
> {code}
> assert dummies*.name == ["dummy one", "dummy two"]
> {code}
> reproduced with groovy-2.4.4 and 2.4.10.
> same behavior if the list is defined inline or if the list is assigned to a variable first.
> thanks, zyro



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
Loading...