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

Statically imported method vs other methods with the same name

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.0-beta-1, 2.5.16, 3.0.10
    • Compiler
    • None

    Description

      Assume you have a class test.Foo:

      package test
      
      class Foo {
        static foo() {'foo'}
      }
      

      Let's consider some code snippets. IMHO Groovy incorrectly resolves reference 'foo' to statically imported method in all of these cases.

       
      import static test.Foo.foo
      
      class Bar {
        def foo() {'bar'}
      
        class Inner {
          def abc() {
            assert foo() == 'bar' //statically imported method will be invoked here
          }
        }
      
      }
      
       
      import static test.Foo.foo
      
      class Bar {
        def foo() {'bar'}
      }
      
      new Bar().with {
        assert foo() == 'bar' //statically imported method will be executed
      }
      
       
      import static test.Foo.foo
      
      class Base {
        def foo(){'base'}
      }
      
      class Bar extends Base {
        def abc() {
          assert foo() == 'base' //statically imported method will be executed 
        }
      }
      

      Attachments

        Activity

          People

            emilles Eric Milles
            mxm-groovy Maxim Medvedev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m