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

clear variable declarationi is need

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-JSR-2
    • lexer, parser
    • None

    Description

      I'm suffering from the collaped variable name scope of Groovy.


      class VarsC {
      p = 1
      f1()

      { p = 'a' }

      f2(p)

      { p = p }

      f3(p)

      { this.p = p }

      }

      v = new VarsC()
      assert v.p == 1

      v.f1()
      assert v.p == 'a'

      v.f2('hello')
      assert v.p == 'a'

      v.f3("hello")
      assert v.p == 'hello'

      I cannot have a local var with the same name as the class field.
      Arguments can clash with class fields too.

      What I need is something to indicate that I'm declaring a new variable in the current scope, something like "var" or "any" or anything, even variable decorators used in Ruby.

      This will help the ClassGenerator too in dealing cases such as nested closures.

      Attachments

        Issue Links

          Activity

            People

              blackdrag Jochen Theodorou
              bingran Bing Ran
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: