Daniil Ovchinnikov created GROOVY-8394:
------------------------------------------

             Summary: @CompileStatic doesn't respect resolve strategy on 
closures
                 Key: GROOVY-8394
                 URL: https://issues.apache.org/jira/browse/GROOVY-8394
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation, Static Type Checker
    Affects Versions: 2.4.13
            Reporter: Daniil Ovchinnikov


{code}

class Root {
  Parent parent = new Parent()

  def parent(@DelegatesTo(Parent) Closure cl) {
    cl.delegate = parent
    cl()
  }
}

class Parent {
  Child child = new Child()

  def child(@DelegatesTo(Child) Closure cl) {
    cl.delegate = child
    cl()
  }

  def foo() { "parent" }
}

class Child {
  def foo() { "child" }
}

@groovy.transform.CompileStatic
def usage() {
  new Root().parent {
    child {
      foo()
    }
  }
}

println usage()
{code}

Expected result: {{parent}}
Actual result: {{child}}

Closure inside {{child {}}} call has default resolve strategy, i.e. 
owner first. Its owner is a closure passed to {{parent {}}}, which is 
delegated to {{Parent}}, which in turn has the method {{foo}}.

Works properly without {{@CompileStatic}}.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to