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

Enum constructor with value throws "unexpected token" error

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.6
    • Fix Version/s: 2.4.7
    • Component/s: Compiler
    • Labels:
      None
    • Environment:
      Windows 7 Professional
      JDK 1.8.0_45

      Description

      First time submitter to this JIRA so let me know if I've specified anything incorrectly. I just upgraded from 2.4.4 to 2.4.6 and now declaring an enum constructor accepting a value as follows:

      UsStates.groovy
      enum UsState {
        
        ID('Idaho'),
        IL('Illinois'),
        IN('Indiana'),
        
        UsState( String value ) { this.value = value }
      
        private final String value
        
        String toString() { return value }
      
      }
      
      println UsState.ID //Idaho
      

      throws the following compile error:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      C:\svn_qa\jenkins_trunk\scripts\UsStates.groovy: 7: unexpected token: this @ line 7, column 29.
           UsState( String value ) { this.value = value }
                                     ^
      
      1 error
      

      No such error occurred in 2.4.4, nor does it happen in 2.4.5. Here are a few contrasting things that do seem to work in 2.4.6:

      UsStatesBoring.groovy
      enum UsState {
        
        ID,
        IL,
        IN,
      
      }
      
      println UsState.ID //ID
      
      UsStatesNoEnum.groovy
      class UsState {
        
        UsState( String value ) { this.value = value }
      
        private final String value
        
        String toString() { return value }
      
      }
      
      final idaho = new UsState('Idaho')
      println idaho //Idaho
      

      Though this seems higher priority than Minor, I can work around it by simply downgrading to 2.4.5. I wish there was a Medium priority.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                paulk Paul King
                Reporter:
                brianeray Brian Ray
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: