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

Casting of arguments in @NamedVariant method has no effect

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0.6
    • 4.0.8
    • None

    Description

      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)
          }
      }
      

      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

      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, []]

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

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              pshevche Pavlo Shevchenko
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: