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

Compile error during static compilation (missing type derivation?)

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

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.17, 3.0.11
    • 3.0.12, 2.5.22
    • Compiler
    • None
    • Gradle, Windows

    Description

      Hi all!

      The following code doesn't compile on my machine with Groovy 3.0.11. But it does compile with 3.0.10 and 4.0.2:

      @CompileStatic
      class TestClass2 {
          def <T extends Number> Set<T> fill(Iterable<T> a_consumable) {
              Set<T> result = new HashSet<>()
              a_consumable.forEach { result.add(it) }
              return result
          }
      }
      

      The compilation fails with the following output:

      9: [Static type checking] - Cannot call java.util.HashSet <T>#add(T) with arguments [java.lang.Object]
      

      Expected behavior:
      AFAICT, this code should compile, as the type of it can be derived.

      Additional remarks:
      Interestingly, the code compiles if I replace {{ <T extends Number> }} with just {{ <T> }}. An explicit cast also helps. So workaround is easy.

      If you need more info, feel free to ask!

      Attachments

        Issue Links

        Activity

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

          People

            emilles Eric Milles
            ChrisBriem Chris Briem
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment