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

No compilation error for GString values in named parameter consturctors for String fields

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-rc-3
    • 2.0-rc-4
    • Static Type Checker
    • None

    Description

      The static type checker currently complains about constructors taking named parameters when a value is a GString for a field which is a String. It should coerce transparently.

      Here's an example showing the problem:

      import groovy.transform.CompileStatic
      
      class User {
          String login
          String username
          String domain
          String firstName
          String lastName
      }
      
      @CompileStatic
      class UserNamedParameterIssueWithStaticCompilation {
          List<User> getUsers() {
              [1, 2, 3].collect { Number num ->
                   new User(
                          login:      "login$num",
                          username:   "username$num",
                          domain:     "domain$num",
                          firstName:  "first$num",
                          lastName:   "last$num"
                  )
              }
          }
      }
      
      def service = new UserNamedParameterIssueWithStaticCompilation()
      service.getUsers()
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: