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

SC: put entry replaced write field for public and protected of map-based type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.0, 5.0.0-alpha-8
    • 5.0.0-alpha-9
    • Static compilation
    • None

    Description

      Consider the following:

      class M implements Map<String,Object> {
        @Delegate Map<String,Object> map = [:].withDefault{ 'entry' }
      
        public        a = 'field'
        protected     b = 'field'
        @PackageScope c = 'field'
        private       d = 'field'
        Closure       e = { 'callable' }
      }
      
      @groovy.transform.CompileStatic
      void test(M map) {
        map.a = null // SC: 6549 (Groovy 4+)
        map.b = null // SC: 6549 (Groovy 4+)
        map.c = null
        map.d = null
        map.e = null
      
        println map // expect: [c:null, d:null]
      }
      
      test(new M())
      

      Running this script prints "[a: null, b: null, c: null, d: null]" since Groovy 4. The prior behavior was to write to public and protected fields, which is the behavior you get if you disable static compilation.

      GROOVY-6954, GROOVY-11367

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: