[
https://issues.apache.org/jira/browse/GROOVY-10133?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles updated GROOVY-10133:
---------------------------------
Description:
In addition to the issues noted in GROOVY-5245, GROOVY-6097, GROOVY-9382 and
GROOVY-9851, there are inconsistencies when both "get" and "is" options are
available for boolean properties.
Consider the following:
{code:groovy}
class C {
boolean isX() { true }
boolean getX() { false }
void test() {
println x // "get"
println this.x // "get"
}
}
new C().test()
println new C().x // "get"
class D extends C {
void test2() {
println x // "is"
println this.x // "is"
println super.x // "get"; GROOVY-1736 converts to "super.getX()";
GROOVY-6097 notes MME if no getter exists
}
}
new D().test() // consistent with "new C().test()"
new D().test2() // see notes above
println new D().x // "is"
// and for additional reference:
class Cat {
static boolean isX(self) { true }
static boolean getX(self) { false }
}
use (Cat) {
println x // "get"
println 'str'.x // "get" -- see GROOVY-5245 for isser only
}
{code}
"getter" is preferred for the declaring class, but this switches to "isser"
preference for subclasses. Not sure if traits or default interface methods
conform to this. *Using {{@CompileStatic}} the preference is for "getter" in
all cases.*
Lastly, when adding an explicit "getter" to a subclass ({{D}} in this example),
the "isser" preference remains. It would be nice to have some kind of compiler
warning for overriding the "getter" but not the "isser" (or vice versa) for a
[Bb]oolean property.
was:
In addition to the issues noted in GROOVY-5245, GROOVY-6097, GROOVY-9382 and
GROOVY-9851, there are inconsistencies when both "get" and "is" options are
available for boolean properties.
Consider the following:
{code:groovy}
class C {
boolean isX() { true }
boolean getX() { false }
void test() {
println x // "get"
println this.x // "get"
}
}
new C().test()
println new C().x // "get"
class D extends C {
void test2() {
println x // "is"
println this.x // "is"
println super.x // "get"; GROOVY-1736 converts to "super.getX()";
GROOVY-6097 notes MME if no getter exists
}
}
new D().test() // consistent with "new C().test()"
new D().test2() // see notes above
println new D().x // "is"
// and for additional reference:
class Cat {
static boolean isX(self) { true }
static boolean getX(self) { false }
}
use (Cat) {
println x // "get"
println 'str'.x // "get" -- see GROOVY-5245 for isser only
}
{code}
"getter" is preferred for the declaring class, but this switches to "isser"
preference for subclasses. Not sure if traits or default interface methods
conform to this. And {{@CompileStatic}} may yield different results.
Lastly, when adding an explicit "getter" to a subclass ({{D}} in this example),
the "isser" preference remains. It would be nice to have some kind of compiler
warning for overriding the "getter" but not the "isser" (or vice versa) for a
[Bb]oolean property.
> Inconsistent method selection for [Bb]oolean properties
> -------------------------------------------------------
>
> Key: GROOVY-10133
> URL: https://issues.apache.org/jira/browse/GROOVY-10133
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.14, 3.0.8
> Reporter: Eric Milles
> Priority: Major
>
> In addition to the issues noted in GROOVY-5245, GROOVY-6097, GROOVY-9382 and
> GROOVY-9851, there are inconsistencies when both "get" and "is" options are
> available for boolean properties.
> Consider the following:
> {code:groovy}
> class C {
> boolean isX() { true }
> boolean getX() { false }
> void test() {
> println x // "get"
> println this.x // "get"
> }
> }
> new C().test()
> println new C().x // "get"
> class D extends C {
> void test2() {
> println x // "is"
> println this.x // "is"
> println super.x // "get"; GROOVY-1736 converts to "super.getX()";
> GROOVY-6097 notes MME if no getter exists
> }
> }
> new D().test() // consistent with "new C().test()"
> new D().test2() // see notes above
> println new D().x // "is"
> // and for additional reference:
> class Cat {
> static boolean isX(self) { true }
> static boolean getX(self) { false }
> }
> use (Cat) {
> println x // "get"
> println 'str'.x // "get" -- see GROOVY-5245 for isser only
> }
> {code}
> "getter" is preferred for the declaring class, but this switches to "isser"
> preference for subclasses. Not sure if traits or default interface methods
> conform to this. *Using {{@CompileStatic}} the preference is for "getter" in
> all cases.*
> Lastly, when adding an explicit "getter" to a subclass ({{D}} in this
> example), the "isser" preference remains. It would be nice to have some kind
> of compiler warning for overriding the "getter" but not the "isser" (or vice
> versa) for a [Bb]oolean property.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)