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

STC: field or property with parameterized SAM-type and closure initializer

    XMLWordPrintableJSON

Details

    Description

      In static mode, the compiler correctly coerces closures that match non-generic SAMs to their concrete type, but this breaks in the context of generics.

      Runnable doIt = { '123' } // works fine
      Supplier<String> supplier = { '123' } // error
      

      The error is

      Cannot assign value of type groovy.lang.Closure <java.lang.String> to variable of type java.util.function.Supplier <String>
      

      Not sure if it's relevant that the generic in the second case is reported as bare <String>. Replacing the type parameter with a literal <java.lang.String> causes the error message to match but does not fix the error. Using <Function<String, String> produces matching behavior, so it's not just a "skip java.lang", and in the latter case the reported bound is the raw type Function.

      Attachments

        Activity

          People

            emilles Eric Milles
            chrylis Christopher Smith
            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