Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.0.21, 5.0.0-alpha-8, 4.0.21
-
None
Description
Properties within a closure are satisfied first against the closure followed by the resolve strategy. This is implemented by: https://github.com/apache/groovy/blob/0e8718d6bafba61daf962892c9d7ae10832b62e0/src/main/java/groovy/lang/Closure.java#L280
The type checker supports this here: https://github.com/apache/groovy/blob/0e8718d6bafba61daf962892c9d7ae10832b62e0/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L648
The properties "class" and "metaClass" are missing from the switch. "class" is not possible as a variable. However, "metaClass" is and should refer to the Closure's meta class, not the delegate or owner's meta class. This can be checked by running:
@groovy.transform.TypeChecked void test(object) { object.with { print metaClass } } test("")
This script should print something like "org.codehaus.groovy.runtime.metaclass.ClosureMetaClass@17d2ed1b[class Sample$_test_closure1]".