Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.13
-
None
Description
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()
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.