You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/06/11 19:01:00 UTC

[jira] [Created] (GROOVY-10133) Inconsistent method selection for [Bb]oolean properties

Eric Milles created GROOVY-10133:
------------------------------------

             Summary: 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
            Reporter: Eric Milles


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 isBooleanProp(self) { true }
  static boolean getBooleanProp2(self) { false }
}
use (Cat) {
  println booleanProp // "get"
  println 'str'.booleanProp // GROOVY-5245
}
{code}

"getter" is preferred from within the declaring class and from outside but this switches to "isser" preference for subclasses.  Not sure if traits or default interface methods conform to this.

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)