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

A static method call inside a static closure bypasses closure delegate behavior

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.5
    • Fix Version/s: 2.1.7, 2.2.0-beta-2
    • Component/s: None
    • Labels:
      None

      Description

      Given the following code:

      class Website {
          Long id
          String url
          Load load
          
          static constraints = {
              Website.load 1
              load nullable:true
              url url:true
          }
          
          static Website load(Long id) {
              Website.get(id)
          }
      }
      
      class Load {
          Long id
          Integer connections
      }
      

      The call to:

      load nullable:true
      

      Will not go through the closure and instead dispatch directly as a static method call. This means it is impossible to control DSL definition. At the AST level the above call seems to be a StaticMethodCallExpression. This is strange because:

      Website.load 1
      

      Is a normal method call expression. Method calls defined in static closures should never be StaticMethodCallExpression instances otherwise a DSL author cannot control the method dispatch.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                blackdrag Jochen Theodorou
                Reporter:
                graemerocher Graeme Rocher
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: