Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10133

Inconsistent method selection for [Bb]oolean properties

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.14, 3.0.8, 4.0.0-alpha-3
    • Fix Version/s: 4.0.0-beta-1
    • Component/s: None
    • Labels:
      None

      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:

      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
      }
      

      "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.

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              emilles Eric Milles
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2h
                2h