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

@CompileStatic breaks assign in combination with dereferencing

    XMLWordPrintableJSON

Details

    Description

      @CompileStatic breaks assignment for code like

      @groovy.transform.CompileStatic
      class StaticClass {
          StringHolder holder = new StringHolder()
          String str
      
          StaticClass(String s) {
              str = holder.str = s
          }
      }
      
      class StringHolder {
          String str
      }
      
      def s = new StaticClass('test')
      assert s.holder.str == 'test'
      assert s.str != 'test'
      

      The second assert fails because s.str == null. Without @CompileStatic it works correctly (and as java).

      Attachments

        1. CompileStaticAssignmentTest.groovy
          1 kB
          Florian Freudenberg

        Activity

          People

            daniel_sun Daniel Sun
            flofreud Florian Freudenberg
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: