groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8627) Compile error using NamedParam with value
Date Sat, 16 Jun 2018 03:55:00 GMT

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

ASF GitHub Bot commented on GROOVY-8627:
----------------------------------------

GitHub user paulk-asert opened a pull request:

    https://github.com/apache/groovy/pull/759

    GROOVY-8627: Compile error using NamedParam with value

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/paulk-asert/groovy groovy8627

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/759.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #759
    
----
commit 55dfeb3fce54f674aca9645b989b2779fec06475
Author: Paul King <paulk@...>
Date:   2018-06-16T03:52:21Z

    GROOVY-8627: Compile error using NamedParam with value

----


> Compile error using NamedParam with value
> -----------------------------------------
>
>                 Key: GROOVY-8627
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8627
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.0
>            Reporter: Eric Milles
>            Priority: Major
>
> {{NamedVariantASTTransformation}} has bug checking for presence of {{value}} member.
> {code:java}
>             for (Parameter fromParam : fromParams) {
>                 if (AnnotatedNodeUtils.hasAnnotation(fromParam, NAMED_PARAM_TYPE)) {
>                     AnnotationNode namedParam = fromParam.getAnnotations(NAMED_PARAM_TYPE).get(0);
>                     boolean required = memberHasValue(namedParam, "required", true);
>                     if (getMemberValue(namedParam, "name") == null) {
>                         namedParam.addMember("value", constX(fromParam.getName()));
>                     }
>                     String name = getMemberStringValue(namedParam, "value");
> {code}
> Check here is for {{name}} and if not found, fill in {{value}} from name of annotated
param.  There are 2 problems with this:
> 1. {{NamedParam}} has no {{name}} member
> 2. {{NamedParam}} indicates {{value}} as required (no default value provided in declaration)
> Example that produces error:
> {code:groovy}
> import groovy.transform.*
> @ToString(includeNames=true)
> class Color {
>   Integer r, g, b
> }
> @NamedVariant
> String m(@NamedDelegate Color color, @NamedParam(value='a', required=true) int alpha)
{
>   return [color, alpha].join(' ')
> }
> print m(r:1, g:2, b:3, a: 0)
> {code}
> Compiling this script results in this error because the {{@NamedParam}} annotation already
has a {{value}} member when this line from the transform is executed: {{namedParam.addMember("value",
constX(fromParam.getName()));}}.
> {code}
> 1. ERROR in Script.groovy (at line 1)\r\n
> 	import groovy.transform.*\r\n
> 	^\n
> Groovy:Groovy compiler error: exception in phase 'semantic analysis' in source unit 'Script.groovy'
Annotation member value has already been added @ line 1, column 0.
> {code}



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

Mime
View raw message