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

Generics regression in method call

    XMLWordPrintableJSON

Details

    Description

      I'm receiving a compile-time error on an invocation that is semantically correct and worked in 4.0.6. When using the EnumMap copy constructor, the STC appears to misinfer the type as <V, V> instead of <K, V>. The problem seems to present itself only when V is also an enum type (of course, K must be an enum type).

      @CompileStatic
      class Example {
      
          enum Foo {}
          enum Bar {}
      
          void run(Map<Foo, Bar> input) {
              error(new EnumMap<>(input))  // error here
          }
      
          void error(Map<Foo, Bar> input) {
          }
      }
      
      Groovy:[Static type checking] - Cannot call Example#error(java.util.Map<Example.Foo, Example.Bar>) with arguments [java.util.EnumMap<Example.Bar, Example.Bar>]	

      Attachments

        Activity

          People

            emilles Eric Milles
            chrylis Christopher Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: