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

Overriding enum methods in constant specific body does not work if non-default constructor is used

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.2
    • Fix Version/s: 2.0.8, 2.1.3, 2.2.0-beta-1
    • Component/s: None
    • Labels:
      None

      Description

      This works as expected:

      enum Country {
          Hungary,
          Italy,
          Poland{ String getCountryCode() { 'pl' } }
          
          String getCountryCode() { 
               name()[0..1].toLowerCase()
           }
      }
      
      assert Country.Hungary.countryCode == 'hu'
      assert Country.Italy.countryCode == 'it'
      assert Country.Poland.countryCode == 'pl'
      

      but if we use a non-default constructor then the following fails on the last assertion:

      enum Country {
          Hungary(1),
          Italy(2),
          Poland(3){ String getCountryCode() { 'pl' } }
      
          
          int population
          
          Country(population) {
              this.population = population
          }
      
           String getCountryCode() { 
               name()[0..1].toLowerCase()
           }
      }
      
      assert Country.Hungary.countryCode == 'hu'
      assert Country.Italy.countryCode == 'it'
      assert Country.Poland.countryCode == 'pl'
      

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              zsolt.varszegi Zsolt Varszegi
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: