Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3156

Within a nested closure, "this.method()" works incorrectly if parent closure and outermost class have closures/methods of the same name

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6-beta-1
    • 1.6-rc-1, 1.5.8, 1.7-beta-1
    • class generator
    • None
    • java version "1.5.0_04" on Windows XP

    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()
          }
      }
      

      Attachments

        1. 3156Patch.zip
          2 kB
          Roshan Dawrani

        Issue Links

          Activity

            People

              roshandawrani Roshan Dawrani
              roshandawrani Roshan Dawrani
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: