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

spreadMap type inference is incorrect and STC reports on valid code

    XMLWordPrintableJSON

Details

    Description

      STC reports false error on spreadMap operation:

      @groovy.transform.TypeChecked
      def f() {
          Map<String, Integer> map1 = [ *:[A:1], *:[B:2]] // [Static type checking] - Incompatible generic argument types. Cannot assign java.util.LinkedHashMap <java.util.Map, java.util.LinkedHashMap> to: java.util.Map <String, Integer>
          assert map1  == [A:1, B:2]
          println map1
      
          Map<String, Integer> submap1 = [A: 1]
          Map<String, Integer> submap2 = [B: 2]
          Map<String, Integer> map2 = [*:submap1, *:submap2] // [Static type checking] - Incompatible generic argument types. Cannot assign java.util.LinkedHashMap <java.util.Map, java.util.LinkedHashMap> to: java.util.Map <String, Integer>
          assert map2  == [A:1, B:2]
          println map2
      }
      
      f()
      
      

      Attachments

        Activity

          People

            emilles Eric Milles
            uehaj UEHARA Junji
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: