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

Wrong method accessed via aliased import

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.12
    • None
    • Compiler
    • None

    Description

      com/foo/Bar.java
      package com.foo;
      
      public class Bar {
          public static Object getSome() {
              System.out.println("getter");
              return 42;
          }
          public static void setSome(Object a) {
              System.out.println("setter " + a);
          }
      }
      
      getterAsSetter.groovy
      import static com.foo.Bar.getSome as setAbc
      
      setAbc()  // prints 'getter' as expected
      setAbc(2) // throws MME as expected (No signature of method: static com.foo.Bar.getSome() is applicable)
      abc = 2   // prints 'setter 2'; should throw MME, because it's equivalent to setAbc(2)
      
      setterAsGetter.groovy
      import static com.foo.Bar.setSome as getAbc
      
      getAbc(null)  // prints 'setter null' as expected
      getAbc()      // prints 'setter null' as expected, equivalent to getAbc(null)
      abc           // prints 'getter'; should print 'setter null', because it's equivalent to getAbc()
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              daniilo Daniil Ovchinnikov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: