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

Wrong method resolution for an overridden method with varargs and covariant return type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.5
    • 2.4.6
    • Static Type Checker
    • None

    Description

      Consider the following code:

      class A {}
      class B {
          Object m(Object[] args) {
              new Object()
          }
      }
      class C extends B {
          A m(Object[] args) {
              new A()
          }
      }
      C c = new C()
      A a = c.m()
      

      It has 50% chance of failing the static type check at the last line, because the STC can resolve to the base definition (with an Object return type) instead of the override, as it doesn't give precedence to the most specific definition in the "varargs with 0 argument" case.

      Like for GROOVY-7710, I have a fix for the bug, but it's also based on my pull request for GROOVY-7420 as it's once again in the same method. It's actually in the same commit, because once refactored a bit, the 2 missing method calls become obvious.

      Attachments

        Activity

          People

            pascalschumacher Pascal Schumacher
            fpavageau Frank Pavageau
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: