Re: Get reference to enclosing closure

2018-07-07 Thread Leonard Brünings
Hi Jochen, it took me some time to get back to you ;) You can check out the code here: https://github.com/spockframework/spock/tree/closure-reference-expression Here is the travis build https://travis-ci.org/spockframework/spock/builds/401275894 If I run the tests in Idea it all works fine, but

Re: Get reference to enclosing closure

2017-11-21 Thread Leonard Brünings
Great now I run into another problem, spock uses groovy-all, which repackages asm. The BytecodeExpression has a MethodVisitor from asm, which is now in groovyjarjarasm.asm.MethodVisitor This compiles fine, but when the AST transforms are executed it breaks down with this exception: Caused by:

Re: Get reference to enclosing closure

2017-11-21 Thread Jochen Theodorou
On 21.11.2017 21:43, Leonard Brünings wrote: Hi Jochen, your first suggestion might do the trick and if closures disappear then there will be much more that doesn't work. We currently do something like this: public void replaceImplicitThis(Expression invocation) { if (invocation ins

Re: Get reference to enclosing closure

2017-11-21 Thread Leonard Brünings
Hi Jochen, your first suggestion might do the trick and if closures disappear then there will be much more that doesn't work. We currently do something like this:   public void replaceImplicitThis(Expression invocation) {     if (invocation instanceof MethodCallExpression) {   MethodCall

Re: Get reference to enclosing closure

2017-11-21 Thread Jochen Theodorou
I am not saying I am getting the question fully... but what you want is def c = { return XY } assert c() == c something like that? Extend BytecodeExpersion and do a "ALOAD 0". No guarantees that this will work forever though. In the future there might be no closure class anymore. Oh and if

RE: Get reference to enclosing closure

2017-11-20 Thread eric.milles
e "contains" can come from. with(list) { SpockRuntime.verifyMethodCondition(this, "contains", [1]) } From: Leonard Brünings [mailto:groovy-...@bruenings-it.net] Sent: Monday, November 20, 2017 5:52 PM To: dev@groovy.apache.org Subject: Re: Get reference to enclosing closure Spock doesn'

Re: Get reference to enclosing closure

2017-11-20 Thread Leonard Brünings
Spock doesn't rewrite it to `this.getThisObject()`. This is what Spock does |with(list) {| |   SpockRuntime.verifyMethodCondition(this, "contains", [1])| |} | |The transformation from `this` to `this.getThisObject()` is done by groovy at a later stage. My guess somewhere in the AST-to-Bytec

RE: Get reference to enclosing closure

2017-11-20 Thread eric.milles
When you rewrite to this form: with(list) { SpockRuntime.verifyMethodCondition(this.getThisObject(), "contains", [1]) } You've esentially frozen your choice of delegate, owner or this. The dynamic resolution of "implicit this" to one of those is no longer going to happen. I guess you'd ne

Re: Get reference to enclosing closure

2017-11-20 Thread Leonard Brünings
Hi Eric, transforming every implicit method call this way would also break the nested `with` blocks. It would basically be a DELEGATE_ONLY strategy, which would prevent helper methods defined in the class to be used. -Leo Am 20.11.2017 um 21:29 schrieb eric.mil...@thomsonreuters.com: I th

RE: Get reference to enclosing closure

2017-11-20 Thread eric.milles
I think "this" or "getThisObject()" should really be "delegate" or "getDelegate()". From: Leonard Brünings [mailto:groovy-...@bruenings-it.net] Sent: Monday, November 20, 2017 2:27 PM To: dev@groovy.apache.org Subject: Get reference to enclosing closure Hi, I'm Leonard from the Spock framework