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

Paul King resolved GROOVY-10004.
--------------------------------
    Fix Version/s: 4.0.0-alpha-3
       Resolution: Fixed

Proposed PR merged. Currently synthetic accessor methods are ignored if found. 
This is an escape clause which leaves wiggle room for AST transforms at the 
risk of a poorer error message if an AST transform does the wrong thing - 
either some kind of Groovy warning about duplication or in the worst case, a VM 
class error. The escape clause was currently needed for @Field. We could 
consider weakening or removing the escape clause down the track:
 * A more liberal escape clause would be to also ignore @Generated accessor 
methods if found, something to keep in mind if other frameworks end up being 
affected
 * We could remove the escape clause if we rework @Field but maybe other 
frameworks would also be impacted and need this wiggle room anyway

> @Lazy transform should check for explicit getters/setters
> ---------------------------------------------------------
>
>                 Key: GROOVY-10004
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10004
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Minor
>              Labels: breaking
>             Fix For: 4.0.0-alpha-3
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The {{@Lazy}} transform renames the backing field to "make it more hidden" 
> and doesn't provide a setter, hence making the field read-only (apart from 
> reflection tricks).
> {code}
> class Zoo {
>     @Lazy String animal = { 'sloth' }()
>     //void setAnimal(String animal) { this.animal = animal }
>     //String getAnimal() { this.animal }
> }
> {code}
> Here {{animal}} becomes {{$animal}}. The intention is to disallow the fields 
> use anymore apart from the sanctioned initialization code provided by the 
> transform. No attempt is made to rename usages of the field that may 
> otherwise occur within the class. Hence adding an explicit getter or setter 
> in the normal way yields a {{StackOverflowError}} when trying to access the 
> original property or {{MissingFieldException}} if trying to access the field 
> directly, i.e. {{this.@animal}}. The transform should instead issue an error 
> if explicit getters/setters are found. It would still be possible to access 
> the {{$animal}} field (which in general may or may not be initialized) if 
> there was really a need, just not in the standard getter or setter.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to