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

Compilation error incorrectly thrown for covariant return types when original method is private

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.0-beta-3
    • 2.4.2
    • Compiler
    • None

    Description

      This code causes a compilation error:

      class A {
          private String foo() { "1" }
          def bar() { foo() }
      }
      def a = new A()
      assert a.bar() == "1"
      class B extends A {
          Integer foo() {2}
      }
      def b = new B()
      assert b.bar()=="1"
      

      Instead the code should successfully compile and run. The correct value for the return value is interesting. It should return "1" with Java-style semantics.

      If duck-typing was more aggressive it could return 2 but that wouldn't be honoring the inner foo() being private.

      Attachments

        Activity

          People

            melix Cédric Champeau
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: