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

ListWithDefault DGM methods aren't type inference friendly

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.5.0-alpha-1
    • None
    • None

    Description

      For the following script:

      @groovy.transform.CompileStatic
      def method() {
          def list = [].withDefault{ it.longValue() }
          list[0] = list[3]
          assert list[0] == 3 && list[0].class == Long
      }
      
      method()
      

      The list access call list[3] doesn't funnel through the ListWithDefault.getAt(int) method but instead the DGM.getAt(List, int) method since List is the inferred type. The withDefault methods could instead return the more specific type and then the correct type will be inferred and the expected behavior is observed.

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              paulk Paul King
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: