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

compilation error when passing a closure's genericized parameters to a constructor under static compilation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0.7
    • 3.0.8, 4.0.0-alpha-3
    • Compiler
    • None

    Description

      The following code:

      package example
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Tuple2Example {
      
         static <T> void noLongerCompiles() {
            def closure = { T a, T b ->
               return new Tuple2<T, T>(a, b)
            }
            closure("foo", "bar")
         }
      }
      
      

      Compiles in v3.0.6 and earlier, but in v3.0.7 results in the following compiler error:

      [Static type checking] - Cannot find matching method groovy.lang.Tuple2#<init>(T, T). Please check if the declared type is correct and if the method exists. @ line 10, column 11.    return new Tuple2<T, T>(a, b)             ^
      1 error
      

      Because this compiles in all versions prior to 3.0.7, I figure it should compile 3.0.7 too.  Even if it really shouldn't compile the message probably ought to be something about the inability to infer the types of a and b, not that the constructor can't be found.

      Attachments

        Activity

          People

            emilles Eric Milles
            jasongarrett Jason Garrett
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h