[ 
https://issues.apache.org/jira/browse/GROOVY-8703?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16584621#comment-16584621
 ] 

Paul King edited comment on GROOVY-8703 at 8/18/18 10:11 AM:
-------------------------------------------------------------

This is by design as per a requested behavior. From the GroovyDoc:
"... If no arguments with @NamedParam or @NamedDelegate annotations are found 
the
first argument is assumed to be an implicit named delegate ..."

I guess assuming all of them were @NamedParam would be the alternative we could 
have had.

I guess we could make a boolean \{{autoDelegate}} annotation attribute to swap 
between those behaviors. Though, thinking about it a bit more, I wonder if we 
made the right call for the default behavior.


was (Author: paulk):
This is by design as per a requested behavior. From the GroovyDoc:
"... If no arguments with @NamedParam or @NamedDelegate annotations are found 
the
first argument is assumed to be an implicit named delegate ..."

I guess assuming all of them were @NamedParam would be the alternative we could 
have had.

I guess we could make a boolean \{{autoDelegate}} annotation attribute to swap 
between those behaviors.

> NamedVariant on constructor
> ---------------------------
>
>                 Key: GROOVY-8703
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8703
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.1
>            Reporter: Eric Milles
>            Priority: Major
>
> 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...)
> {code:groovy}
> 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'
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to