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

TypeChecking Error when combining generic method and Java Enum

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.0, 2.4.1
    • 2.4.2
    • Static Type Checker
    • None

    Description

      To reproduce:

      import groovy.transform.TypeChecked
      
      import java.nio.file.StandardCopyOption
      
      enum TestEnum {
          A, B, C
      }
      
      @TypeChecked
      class TestGenerics {
          public static <T> List<T> randomSample(T[] sequence) {
              return Arrays.asList(sequence)[0..1]
          }
      
          def test1 = randomSample(TestEnum.values())
          def test2 = randomSample(StandardCopyOption.values())
      }
      

      /tmp/TestGenerics.groovy: 16: [Static type checking] - Cannot call <T> TestGenerics#randomSample(T[]) with arguments [java.nio.file.StandardCopyOption[]]
      @ line 16, column 17.
      def test2 = randomSample(StandardCopyOption.values())

      Same for Collections with Generics instead of arrays.
      Note this fails only with Java enums, not Groovy enums.

      Could be related to patches for:
      https://jira.codehaus.org/browse/GROOVY-5981

      Attachments

        Activity

          People

            melix Cédric Champeau
            tkruse Thibault Kruse
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: