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

@CompileStatic with getAt(int) and getAt(String)

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0-beta-1, 2.5.7
    • Component/s: None
    • Labels:
      None

      Description

      It seems like if I use @CompileStatic, a construct like

      Car specificCar = somethingWithAGetAtMethod[129]
      .. or ..
      Car specificCar = somethingWithAGetAtMethod["AZ1235"]
      

      doesn't work. The compiler says: Groovyc: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type com.example.Car

      This seems strange. The getAt(..)-method in question obviously return a "Car" here.

      This email thread has evidently experienced the same: http://groovy.329449.n5.nabble.com/Unexpected-behaviour-for-getAt-operator-operloading-with-static-compilation-td5744122.html

      .. and the theory is that since this is specified on Groovy's extension of Object, which specifies Object getAt(String), then that might be the culprit. Interesting, though, that Object does not seemingly specify getAt(int), but it still gives the exact same compiler error with both int and String.

      I had this idea that the subscript-operator was "syntactic sugar", which then makes the compiler error hard to understand.

       

       

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              stolsvik Endre Stølsvik
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: