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

TypeChecked/CompileStatic wildcard problems

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

Details

    Description

      The following works fine in 2.x/3x but fails with Groovy 4.0.1

      @groovy.transform.CompileStatic
      class Reproducer {
          
          Map<String, ?> formData = [:]
          
          Map<String, ?> getCsrfTokenField() {
              [:]
          }
          
          def broken() {
      		resolveFormData(formData + csrfTokenField)
          }
          
          static Map<String, String> resolveFormData(Map<String, ?> formData) {
              formData.collectEntries { k, v -> [k, v instanceof Closure ? v().toString() : v] }
          }
          
          static void main(String... args) {
           	println 'compiled successfully'   
          }
      }
      

      Fails with

      [Static type checking] - Cannot call <K,V> org.codehaus.groovy.runtime.DefaultGroovyMethods#plus(java.util.Map<K, V>, java.util.Map<K, V>) with arguments [java.util.Map<java.lang.String, ?>, java.util.Map<java.lang.String, ? extends java.lang.Object>]
       @ line 11, column 19.
      

      Groovy Web Console

      Attachments

        Issue Links

        Activity

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

          People

            emilles Eric Milles
            leonard84 Leonard Brünings
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment