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

STC: check lambda or closure parameter types against target method

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

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.0-rc-1
    • Static Type Checker
    • None

    Description

      Follow up from GROOVY-10277. Consider the following:

      @groovy.transform.TypeChecked
      void test() {
        Comparator<Integer> cmp = (int one, int two) -> Integer.compare(one,two)
      }
      

      Instead of an error for mismatched generics – which was the previous disposition of the compiler – there could be an error for each typed parameter that does not match expectations. ecj produces the following error for the above's Java equivalent: "Lambda expression's parameter one is expected to be of type Integer"

      These checks should extend to lambdas or closures that are cast, coerced or passed as arguments.

      https://github.com/apache/groovy/blob/eb8854afcf02057f70b8a979a873e0a34393b740/src/test/groovy/transform/stc/LambdaTest.groovy#L243

      Attachments

        Activity

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

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment