You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Michael Arndt (JIRA)" <ji...@apache.org> on 2018/04/27 15:17:00 UTC
[jira] [Created] (GROOVY-8562) Wrong Closure delegation for
property access when using @CompileStatic and DELEGATE_FIRST /
DELEGATE_ONLY
Michael Arndt created GROOVY-8562:
-------------------------------------
Summary: Wrong Closure delegation for property access when using @CompileStatic and DELEGATE_FIRST / DELEGATE_ONLY
Key: GROOVY-8562
URL: https://issues.apache.org/jira/browse/GROOVY-8562
Project: Groovy
Issue Type: Bug
Components: Static compilation
Affects Versions: 2.4.15, 2.5.0-rc-1, 2.3.11
Reporter: Michael Arndt
Closures resolve to owner property although `DELEGATE_FIRST`
or `DELEGATE_ONLY` are set as `resolveStrategy`.
This only happens when `@CompileStatic` is used.
This does not apply to method calls.
For Groovy 2.3.11 this only affects read operations.
Only the versions 2.5.0-rc-1, 2.4.15, 2.3.11 have been tested yet.
I will add tests for newer versions, but this requires a different
test framework than Spock.
I have created a demo project at [https://github.com/MeneDev/groovy-bugreport-closure-strategy]
{code:java}
class ADelegate {
def x = "delegate"
}
@CompileStatic
class AClass {
public <T> T closureExecuter(
ADelegate d,
@DelegatesTo(value = ADelegate, strategy = DELEGATE_ONLY) Closure<T> c) {
c.resolveStrategy = DELEGATE_ONLY
c.delegate = d
return c()
}
def x = "owner"
def test() {
def theDelegate = new ADelegate()
def res = closureExecuter(theDelegate) {
return x
}
// is "owner" instead of "delegate"
return res
}
}
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)