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

Static compilation complains when accessing a property with a property notation inside a named arg ctor inside a closure inside a @CompileStatic class

    XMLWordPrintableJSON

Details

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

    Description

      Similarly to GROOVY-5531, I'm facing another problem with the same sample.
      Static type checking the class is fine, but I get a compilation error coming from StaticTypesCallSiteWriter#makeGetPropertySite() when trying to access the closure's parameter property.

      The offending sample:

      import groovy.transform.CompileStatic
      
      class User {
          String login
      }
      
      interface Row<R> {
          R getKey()
      }
      
      class RowImpl<R> implements Row<R> {
          R getKey() { null }
      }
      
      @CompileStatic
      class UserRepository implements Serializable {
          Collection<User> getUsers() {
              def rows = [new RowImpl<String>()]
      
              return rows.collect { Row<String> row ->
                  new User(login: row.key)
              }
          }
      }
      
      def rep = new UserRepository()
      rep.getUsers()
      

      Error I get:

      Access to java.lang.Object#key is forbidden at line: 21, column: 29
      

      Attachments

        Issue Links

          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: