Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.6-beta-1
-
Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
-
Component/s: class generator
-
Labels:None
-
Environment:java version "1.5.0_04" on Windows XP
-
Testcase included:yes
-
Number of attachments :
Description
This issue is related to issue reported in GROOVY-2849, which is reported for same kind of interference for property access inside a nested closure. For easier management of fixes, testing, etc, it was suggsted that for issue with method calls, a separate JIRA bug be created.
Testcase for the issue:
class NestedClosureMethodCallBug extends GroovyTestCase { def void testNestedClosureMethodCall(){ assert m() == "method" assert c1() == "method" } def m = {return "method"} def c1 = { def m = {return "c1"} def c2 = { /* * If both 'm()' and 'this.m()' are used as follows, * 'this.m()' should not resolve to c1 closure's 'm' local variable. * It should resolve to outermost NestedClosureMethodCallBug's 'm()'. */ assert m() == "c1" return this.m() } c2() } }
Issue Links
- depends upon
-
GROOVY-2849
A property name in a nested closure interferes with a class property when refering with "this.prop"
-
- relates to
-
GROOVY-2621
Local variable shadows method in closure call, even if method is called with this keyword.
-
Attaching fix patches for 1.5.8, 1.6-RC1, 1.7-beta-1 versions for this issue.
The fix is along the very same lines of the fix provided for
GROOVY-2849.The modification has been made to AsmClassGenerator's visitMethodCallExpression() to correctly deal with this.m() inside a closure if parent closure defines a closure of the same name.
Hope it helps.
Roshan