Eric Milles created GROOVY-11386:
------------------------------------
Summary: STC: closure property precedence
Key: GROOVY-11386
URL: https://issues.apache.org/jira/browse/GROOVY-11386
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Affects Versions: 4.0.21, 5.0.0-alpha-8, 3.0.21
Reporter: Eric Milles
Assignee: Eric Milles
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:
{code:groovy}
@groovy.transform.TypeChecked
void test(object) {
object.with {
print metaClass
}
}
test("")
{code}
This script should print something like
"org.codehaus.groovy.runtime.metaclass.ClosureMetaClass@17d2ed1b[class
Sample$_test_closure1]".
--
This message was sent by Atlassian Jira
(v8.20.10#820010)