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

Closure parameter type inference error if the receiver is a delegate type

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.0-beta-1
    • Fix Version/s: 2.3.0-beta-2
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      The following code fails with a compile time error ("This should not have happened") because the type inference engine doesn't use the right receiver type.

      import java.util.concurrent.Callable
      
      interface Foo {
          public <T> T background(Callable<T> backgroundOperation)
      }
      class FooImpl implements Foo {
      
          @Override
          def <T> T background(final Callable<T> backgroundOperation) {
              backgroundOperation.call()
          }
      }
      static void test(@DelegatesTo(Foo) Closure cl) {
          cl.delegate = new FooImpl()
          cl()
      }
      
      test {
          background { 'foo' }
      }
      

      Test case adapted from the Ratpack sources.

        Attachments

          Activity

            People

            • Assignee:
              melix Cédric Champeau
              Reporter:
              melix Cédric Champeau
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: