You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Pavlo Shevchenko (Jira)" <ji...@apache.org> on 2022/12/29 13:41:00 UTC

[jira] [Created] (GROOVY-10889) Casting of arguments in `@NamedVariant` method has no effect

Pavlo Shevchenko created GROOVY-10889:
-----------------------------------------

             Summary: Casting of arguments in `@NamedVariant` method has no effect
                 Key: GROOVY-10889
                 URL: https://issues.apache.org/jira/browse/GROOVY-10889
             Project: Groovy
          Issue Type: Bug
    Affects Versions: 4.0.6
            Reporter: Pavlo Shevchenko


{code:java}
import groovy.transform.NamedVariant

class Reproducer {

    @NamedVariant
    private static Tuple2<Integer, Set<String>> createSampleData(
        Integer left = 0,
        Set<String> right = [] as Set
    ) {
        Tuple2.tuple(left, right)
    }

    static void main(String[] args) {
        createSampleData(left: 1)
    }
}
{code}
The default value of "right" argument (i.e. "[] as Set") is detected as "ArrayList" despite the explicit cast. This used to work in Groovy 3.x, and now fails with
{code:java}
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: static dev.pshevche.Reproducer.createSampleData() is applicable for argument types: (Integer, ArrayList) values: [1, []]{code}

Replacing the "[] as Set" with "new HashSet<>()" resolves the issue.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)