You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2016/10/14 20:18:20 UTC

[jira] [Updated] (GROOVY-3976) Improve "with" by ending with implied "return delegate"

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

Paul King updated GROOVY-3976:
------------------------------
    Description: 
In this code:
{code}
class Foo { String bar }
def x = new Foo().with {
  bar = "baz"
}
{code}
"x" is now a String with the value "baz" thanks to the implied return.  To work around this, we have to say:
{code}
def x = new Foo().with {
  bar = "baz"
  return delegate
}
{code}
...which is pretty ugly, to say the least.

So can we modify the "with" syntax to have an implied "return delegate"?  I doubt anyone was depending on the previous behavior for code correctness.

Test will be this:
{code}
class Foo { String bar }
def x = new Foo().with {
  bar = "baz"
}
assert x instanceof Foo
assert x.bar == "baz"
{code}


  was:
In this code:

class Foo { String bar }
def x = new Foo().with {
  bar = "baz"
}

"x" is now a String with the value "baz" thanks to the implied return.  To work around this, we have to say:

def x = new Foo().with {
  bar = "baz"
  return delegate
}

...which is pretty ugly, to say the least.

So can we modify the "with" syntax to have an implied "return delegate"?  I doubt anyone was depending on the previous behavior for code correctness.

Test will be this:

class Foo { String bar }
def x = new Foo().with {
  bar = "baz"
}
assert x instanceof Foo
assert x.bar == "baz"


> Improve "with" by ending with implied "return delegate"
> -------------------------------------------------------
>
>                 Key: GROOVY-3976
>                 URL: https://issues.apache.org/jira/browse/GROOVY-3976
>             Project: Groovy
>          Issue Type: Improvement
>          Components: syntax
>    Affects Versions: 1.7.0
>            Reporter: Robert Fischer
>             Fix For: 4.0
>
>
> In this code:
> {code}
> class Foo { String bar }
> def x = new Foo().with {
>   bar = "baz"
> }
> {code}
> "x" is now a String with the value "baz" thanks to the implied return.  To work around this, we have to say:
> {code}
> def x = new Foo().with {
>   bar = "baz"
>   return delegate
> }
> {code}
> ...which is pretty ugly, to say the least.
> So can we modify the "with" syntax to have an implied "return delegate"?  I doubt anyone was depending on the previous behavior for code correctness.
> Test will be this:
> {code}
> class Foo { String bar }
> def x = new Foo().with {
>   bar = "baz"
> }
> assert x instanceof Foo
> assert x.bar == "baz"
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)