Consider the following:
final class C extends spock.lang.Specification {
static int NUM = 123
def 'with map'() {
given:
def map = [key: 123]
expect:
with(map) {
containsKey('key')
}
}
}
"with" resolves to public <U> void with(@DelegatesTo.Target U target, @DelegatesTo(strategy = Closure.DELEGATE_FIRST) @ClosureParams(FirstParam.class) Closure<?> closure) in Specification. However the perceived type of the delegate is Object because the argument passed was declared using def.

Consider the following:
"with" resolves to
public <U> void with(@DelegatesTo.Target U target, @DelegatesTo(strategy = Closure.DELEGATE_FIRST) @ClosureParams(FirstParam.class) Closure<?> closure)in Specification. However the perceived type of the delegate is Object because the argument passed was declared using def.