groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <eric.mil...@thomsonreuters.com>
Subject RE: Get reference to enclosing closure
Date Tue, 21 Nov 2017 00:17:23 GMT
If this snippet, "this" will always refer to the enclosing class, never the delegate "list"
or the owner (which may be the enclosing closure or "this" if no enclosing closure).  That
is, the choice of "this" has already frozen where "contains" can come from.


with(list) {

  SpockRuntime.verifyMethodCondition(this, "contains", [1])
}


From: Leonard Brünings [mailto:groovy-dev@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'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-Bytecode ASM code as I can see the upper version in the
last stage of the AST-Transforms.


with(list) {

  SpockRuntime.verifyMethodCondition(this.getThisObject(), "contains", [1])
}
Am 20.11.2017 um 22:09 schrieb eric.milles@thomsonreuters.com<mailto:eric.milles@thomsonreuters.com>:
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 need to re-implement
the resolution strategy.

Mime
View raw message