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

SC: Problem accessing a Map string key with property notation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1
    • 2.0.2
    • Static compilation
    • None

    Description

      import groovy.transform.*
      
      @CompileStatic
      class Bug2 {
          void test() {
              Map<String, Integer> m = ['abcd': 1234]
              assert m['abcd'] == 1234
              assert m.abcd == 1234
          }
      }
      
      new Bug1().test()
      

      The code above works fine with static type checking.
      But it's not happy with static compilation for the last line, where we're using the property notation for

      1 compilation error:
      
      Access to java.util.Map <java.lang.String, java.lang.Integer>#abcd is forbidden at line: 8, column: 16
      

      Note that an assignment m.abcd = 1234 seems to be okay though.

      Attachments

        Activity

          People

            melix Cédric Champeau
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: