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

Reference to static member of parent class in enum constructor fails at runtime

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.3.0
    • 2.5.15, 3.0.8, 4.0.0-alpha-3
    • Compiler
    • Mac OS X running STS in a Grails context

    Description

      I have a class with the following code:

      class UnitGroupMap {
        ...
        static Map suffixPriority = ['a' : 10, 'b' : 20]
        ...
        enum UnitGroup {
          SAMPLE("foo"),
          ...
          UnitGroup(String name) {
            ...
            suffixPriority[name] = priority
            ...
          }
        ...
        }
        ...
      }
      

      The compiler does not complain, STS doesn't complain, but at runtime, there's an exception that "suffixPriority" is not a member of UnitGroupMap.UnitGroup.

      To make this code work, I have to precede the suffixPriority reference with the class name: UnitGroupMap.suffixPriority

      Either this should work as written, or the compiler should generate an error or at least a warning. However, STS at least highlights suffixPriority in italics as though it can and does see the field should be coming from the parent class, UnitGroupMap.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              mitsu Mitsu Hadeishi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: