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

Anonymous inner class believes protected method in parent's superclass returns Object

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.7
    • 2.4.8
    • groovy-runtime
    • None

    Description

      The below will execute the constructor on `Other` that takes an `Object`, even though `getName()` returns a `String`.

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Parent {
          protected String getName() {
              "sally"
          }
      }
      
      @CompileStatic
      class Child extends Parent {
      
          Inner doSomething() {
              return new Inner() {
                  void go() {
                      new Other(name)
                  }
              }
          }
      
      }
      
      @CompileStatic
      class Other {
          Other(Object object) {
              println "called with other"
          }
          Other(String string) {
              println "called with string"
          }
      }
      
      @CompileStatic
      abstract class Inner {
          abstract void go()
      }
      
      Inner inner = new Child().doSomething()
      inner.go()
      

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              Schlogen James Kleeh
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: