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

CompileStatic conues field access with property access

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.0.4
    • Component/s: Static compilation
    • Labels:
      None
    • Environment:
      JDK 1.7.0_04

      Description

      When accessing field 'x' that have the same name as property 'getX'
      compiler try to access the property instead of field.

      If you remove the property accessor 'getX' then error disappears

      I don't know if it just compile time or also run-time.

      The complete test case below demonstrates it:

      class CSFieldConfuseProperty {
      
        private AtomicBoolean x;
      
      
        @CompileStatic
        public boolean getX() {
          return x.get();
        }
      
        /**
         * This one gives error:
         * Groovyc: [Static type checking] - Cannot find matching method boolean#set(boolean).
         * Please check if the declared type is right and if the method exists.
         */
        @CompileStatic
        public void setX1(boolean flag) {
          this.x.set(flag);
        }
      
        /**
         * This cone is compiled OK
         */
        public void setX2(boolean flag) {
          this.x.set(flag);
        }
      
      }
      

        Attachments

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              boaznahum Boaz Nahum
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: