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

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

blackdrag commented on code in PR #3295:
URL: https://github.com/apache/groovy/pull/3295#discussion_r4555727737


##########
src/test/groovy/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy:
##########
@@ -326,6 +326,24 @@ final class NamedVariantTransformTest {
         '''
     }
 
+    @Test // GROOVY-10498
+    void testFalsyPositionalArgumentOverridesDefaultValue() {
+        assertScript shell, '''
+            @ToString(includeNames=true)
+            class Color {
+                int r, g, b
+            }
+
+            @NamedVariant
+            String m(@NamedDelegate Color color, Number alpha = 4.5) {
+                return "$color $alpha"
+            }
+
+            assert m(r:1, g:2, b:3, 0.0) == 'Color(r:1, g:2, b:3) 0.0'
+            assert m(r:1, g:2, b:3, 9) == 'Color(r:1, g:2, b:3) 9'

Review Comment:
   you should add "assert m(r:1, g:2, b:3) == 'Color(r:1, g:2, b:3) 4.5'" to 
proof the default argument is still taken into consideration





> NamedVariant: default value overrides supplied value if it's falsy 
> (positional parameter)
> -----------------------------------------------------------------------------------------
>
>                 Key: GROOVY-10498
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10498
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.10, 4.0.0
>            Reporter: Eric Milles
>            Priority: Major
>              Labels: named-parameters
>
> Consider the following:
> {code:groovy}
> import groovy.transform.*
> @ToString(includeNames=true)
> class Color {
>   int r, g, b
> }
> @NamedVariant
> String m(@NamedDelegate Color color, Number alpha=4.5) {
>   return [color, alpha].join(' ')
> }
> print m(r:1, g:2, b:3, 0.0) // "Color(r:1, g:2, b:3) 4.5"!
> {code}



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to