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

ASF GitHub Bot commented on GROOVY-12520:
-----------------------------------------

codeconsole opened a new pull request, #3046:
URL: https://github.com/apache/groovy/pull/3046

   When a superclass declares both `isX()` and `getX()`, the property `x` is 
read through `isX()` (GROOVY-10133). In a class that overrides `isX()` or 
declares a `boolean x` property, `super.x` called `getX()` instead, in dynamic 
Groovy and under `@TypeChecked`. It now calls `isX()`, as `@CompileStatic`, 
`this.x` and Groovy 4.0.33 do. This is a regression in 5.0.0.
   
   ```groovy
   class C {
       boolean isX() { true }
       boolean getX() { false }
   }
   class D extends C {
       boolean isX() { false }
       boolean test() { super.x }  // false (getX); now true (C.isX), as in 
4.0.33
   }
   ```
   
   Split out of #3044.
   
   ## How
   
   For `super` usage, the getter of a method the subclass overrides is the MOP 
method `super$N$isX`. The check that keeps `isX()` over `getX()` only accepted 
names starting with `is`, so `getX()` replaced it. The check now looks past the 
MOP prefix. The order in which the accessors are indexed changed in 5.0.0, 
which is why 4.0.33 was not affected.
   
   ## Tests
   
   `bugs.Groovy10133`, for an overriding `isX()` and for a `boolean x` 
property, in all three modes, and in a closure in dynamic Groovy and under 
`@TypeChecked`. They fail without the change. 14,936 tests in the `groovy`, 
`gls`, `bugs`, `org.codehaus.groovy.classgen`, `transform`, `runtime`, 
`reflection`, `vmplugin`, `control` and `ast` packages and the stub generator 
tests pass. `groovy-contracts`, `groovy-typecheckers`, `groovy-ginq`, 
`groovy-macro-library`, `groovy-json`, `groovy-xml` and `groovy-templates` pass 
their tests, and every subproject compiles its main and test sources. The 
Checkstyle and CodeNarc gates pass.
   
   Being a regression in 5.0.0, this may be worth backporting to `GROOVY_5_0_X` 
and `GROOVY_6_0_X`.
   




> super.x calls getX() instead of isX() when the class overrides isX()
> --------------------------------------------------------------------
>
>                 Key: GROOVY-12520
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12520
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> When a class declares both {{isX()}} and {{getX()}}, Groovy reads the 
> property {{x}} through {{isX()}} (GROOVY-10133), also through {{super}}. If 
> the subclass overrides {{isX()}} or declares a {{boolean x}} property, 
> dynamic Groovy and {{@TypeChecked}} read {{super.x}} through the superclass's 
> {{getX()}} instead:
> {code:groovy}
> class C {
>     boolean isX() { true }
>     boolean getX() { false }
> }
> class D extends C {
>     boolean isX() { false }
>     boolean test() { super.x }
> }
> class E extends C {
>     boolean x
>     boolean test() { super.x }
> }
> assert new D().test() // fails: false
> assert new E().test() // fails: false
> {code}
> {{@CompileStatic}} returns {{true}} for both, and so does dynamic Groovy 
> 4.0.33. 5.0.0, 5.0.8, 6.0.0 and master return {{false}}.
> For {{super}}, the getter of an overridden method is the MOP method 
> {{super$2$isX}}, and the check that keeps {{isX()}} over {{getX()}} only 
> accepts a method whose name starts with "is", so {{getX()}} replaces it.
> Expected: {{super.x}} calls {{C.isX()}} in every mode.
> PR: https://github.com/apache/groovy/pull/3044



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

Reply via email to