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

Compiler should not allow enum constructor calls from outside the enum

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.7.2, 1.8-beta-1
    • None
    • None

    Description

      Currently groovy compiler lets enum constructor invocations from outside the enum class (and its sub-classes) get compiled. Such calls fail at runtime because enum constructors are transformed to add 2 additional parameters in front of the user-provided parameters - 1) identifier, 2) ordinal.

      enum Alphabet {
      	A(1), Z(26)
      	private int m_pos;
      
      	public Alphabet( int pos ) {
      		m_pos = pos;
      	}
      }
      
      /* compiler should reject this invocation as enum constructor are only for internal purposes */
      println new Alphabet(2) 
      

      In the code above, the call "new Alphabet(2)" fails at runtime because including the 2 internally added parameters, the constructor is <(String,II)V> and not <(I)V>.

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            roshandawrani Roshan Dawrani
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: