groovy
  1. groovy
  2. GROOVY-4145

Statically imported fields & properties

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.1
    • Fix Version/s: 1.7.2, 1.8-beta-1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Create class Foo

      class Foo {
        static foo=2
        static getFoo(){
          return 3
        } 
      }
      

      and a script

      import static Foo.foo
      
      print foo
      

      This script calls getter getFoo and prints "3".
      But if you delete declaration "static foo=2" from the class the script fails with MissingPropertyException.
      IMHO the script should call getter in both cases.

        Issue Links

          Activity

          Hide
          Paul King added a comment -

          Groovy has never (intentionally) supported

          import static Foo.foo
          

          as anything other than a shorthand for getting to a foo field. But as this issue showed, there was an unintentional case where the property rather than the field was used.

          Given that there is another issue open about this topic (GROOVY-4153), instead of reopening this one, any further clarifications wrt desired behavior will occur as part of that issue.

          Show
          Paul King added a comment - Groovy has never (intentionally) supported import static Foo.foo as anything other than a shorthand for getting to a foo field. But as this issue showed, there was an unintentional case where the property rather than the field was used. Given that there is another issue open about this topic ( GROOVY-4153 ), instead of reopening this one, any further clarifications wrt desired behavior will occur as part of that issue.
          Hide
          Roshan Dawrani added a comment -

          I thought is was half not-working. Now coming to know that it was half working by mistake.

          I assumed that absence of any comments refuting the requirements of this JIRA meant that the requirements were valid. I guess I should have explicitly asked.

          Show
          Roshan Dawrani added a comment - I thought is was half not-working. Now coming to know that it was half working by mistake. I assumed that absence of any comments refuting the requirements of this JIRA meant that the requirements were valid. I guess I should have explicitly asked.
          Hide
          Paul King added a comment -

          No problems Roshan, no-one picked up the error. Now we have to work out best way forward. Affects GROOVY-3945 too which is even older!

          There is nothing inherently wrong with supporting some kind of property shorthand. It just hasn't been covered yet and there are some tricky cases which might make it harder than it looks.

          Show
          Paul King added a comment - No problems Roshan, no-one picked up the error. Now we have to work out best way forward. Affects GROOVY-3945 too which is even older! There is nothing inherently wrong with supporting some kind of property shorthand. It just hasn't been covered yet and there are some tricky cases which might make it harder than it looks.
          Hide
          Paul King added a comment -

          OK, I added in the property syntax in other places, so the fix shouldn't affect this issue.

          Show
          Paul King added a comment - OK, I added in the property syntax in other places, so the fix shouldn't affect this issue.

            People

            • Assignee:
              Roshan Dawrani
              Reporter:
              Maxim Medvedev
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: