A common idiom in many a DSL (e.g. the Gradle DSL) is that we have
For some keyword (e.g. repositories, dependencies, etc.). The keyword switches on some DSL feature inside of the closure block by setting the delegate of the closure.
It would be nice to directly support this kind of idiom. I first though that is what 'delegatesTo' did... but it doesn't.
Right now the 'delegate' is assumed to be the same as the 'receiver' of <keyword> method. That is often but not always correct.
A more complex use case in the Gradle DSLD is the 'configure' method.
This will set the delegate in the closure not to some specific type, but to a type that is derived from <somethings> type. (E.g. <something> is a Project then the delegate will be that project. If something is a list of Project, it will be invoking the closure repeatedly for each project in the list.
This is probably hard/impossible to support, but at least we could support the more easy case where the delegate has a specific and well known type.