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

STC: different errors for map[k] and map.getAt(k)

Agile BoardAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.2
    • Static Type Checker
    • None

    Description

      Follow up to GROOVY-6668. Explicit getAt call produces different error from square-bracket version. Could they both produce the same error? I prefer "Cannot call ... with arguments [groovy.lang.GString]" over the recently introduced "Cannot find matching method ..."

      @groovy.transform.CompileStatic
      void meth() {
        def key = "${'key'}"
        Map<String, String> map = [:]
      
        map[key].toUpperCase() // Cannot find matching method java.lang.Object#toUpperCase(). Please check if the declared type is correct and if the method exists.
        map.getAt(key).toUpperCase() // Cannot call <K,V> java.util.LinkedHashMap <java.lang.String, java.lang.String>#getAt(java.lang.String) with arguments [groovy.lang.GString] 
      }
      

      It appears that the square-bracket version may have selected extension method static Object getAt(Object self, String property).

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment