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

Daniel Sun resolved GROOVY-12658.
---------------------------------
    Fix Version/s: 7.0.0-alpha-1
                   6.0.1
         Assignee: Daniel Sun
       Resolution: Fixed

Fixed on master in b26111c9a4664739298739dbf161fcc29875c7ec 
(https://github.com/apache/groovy/commit/b26111c9a4664739298739dbf161fcc29875c7ec,
 #3179) and on the GROOVY_6_0_X branch in 
0151eb3dc2421c9b00d1bfb235b0be0ad19dbbaa 
(https://github.com/apache/groovy/commit/0151eb3dc2421c9b00d1bfb235b0be0ad19dbbaa).

> Packed closures read and write owner properties as fields, skipping getters 
> and setters
> ---------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12658
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12658
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 7.0.0-alpha-1, 6.0.1
>
>
> A closure packed by closure packing (GEP-27, via {{@PackedClosures}} or 
> {{-Dgroovy.target.closure.pack=true}}) has its body moved into a method of 
> the owner class. There, a property of the owner compiles to direct field 
> access, so the getter and setter are no longer called. The closure class it 
> replaces calls them.
> {code:groovy}
> @groovy.transform.CompileStatic // or @groovy.transform.PackedClosures 
> without @CompileStatic
> @groovy.transform.PackedClosures
> class Box {
>     int gets, sets
>     BigDecimal e = 1
>     BigDecimal getE() { gets++; e }
>     void setE(BigDecimal v) { sets++; e = v }
>     def m() { def r = { -> e++ }(); [r, this.@e, gets, sets] }
> }
> println new Box().m()
> {code}
> *Actual:* {{[1, 2, 0, 0]}}
> *Expected:* {{[1, 2, 1, 1]}}, as without packing.
> The same happens for reads, assignments, compound assignments, prefix and 
> postfix forms, and both {{e}} and {{this.e}}. It also affects a subclass 
> override of a generated accessor, static properties, {{is}} getters, and 
> (dynamic) an owner that overrides {{getProperty}}. 
> {{AsmClassGenerator.visitPropertyExpression}} resolves {{this.name}} to the 
> declared field in any method of the class; the hoisted body is such a method, 
> so it bypasses the accessors.
> Verified on 6.0.0 and master.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to