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

Compilation error when calling method that has Optional<Closure> parameter

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

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.0, 2.4.0-rc-1
    • 2.3.11, 2.4.2
    • Static Type Checker
    • None

    Description

      I'm seeing a strange issue where if I try to call a method with an Optional<Closure> parameter from a type-checked context using Optional.of(someClosure) I get a compilation error. Other type parameters work fine in the same context and weirdly so does Optional.absent().

      I've attached 3 scripts that demonstrate the problem.

      • FailingWithClosure.groovy shows the problem occurring. I have a method that accepts Optional<Closure> and two statically compiled methods that call it, one with Optional.of(someClosure) and one with Optional.absent().
      • WorkingWithString.groovy is the same code but with String type parameters instead of Closure. It works fine.
      • WorkingWithClosureAndCast.groovy shows that if I explicitly cast the argument to Optional<Closure> it works.

      Attachments

        Activity

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

          People

            melix Cédric Champeau
            robfletcher Rob Fletcher
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment