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

Unexpected behavior with @NamedVariant on constructor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.1
    • 3.0.0-alpha-4, 2.5.3
    • None

    Description

      Tried this example and got cast exception converting Map to Integer. Should the print statement at the end use the generated map constructor as expected? (Note: I am compiling with indy variant; tried to use web console to try vanilla MOP...)

      import groovy.transform.*
      import groovy.transform.options.*
      
      @ToString(includeNames=true)
      class Color {
        final Integer r, g, b
      
        @NamedVariant @VisibilityOptions(Visibility.PUBLIC)
        private Color(Integer r, Integer g, Integer b) {
          this.r = r
          this.g = g
          this.b = b
        }
      
        public static final Color BLACK = new Color(0, 0, 0)
      }
      
      print(new Color(g:12, b:42, r:12)) // gives org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{}' with class 'java.util.LinkedHashMap' to class 'java.lang.Integer'
      

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: