@CompileStatic in Groovy 5

Per Nyfelt <[email protected]> Sun, 31 Aug 2025 23:09:02 +0200
Newsgroups gmane.comp.lang.groovy.user
Organization Alipsa HB
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------MvQj0HQ4W5d0Cghad4dscYx8
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi,

In groovy 4 i am able to do this:

I used to be able to do this:

@Override
void setProperty(String propertyName, Object newValue) {
     if (propertyName in columnNames) {
         putAt(propertyName, newValue)
     } else {
         super.setProperty(propertyName, newValue)
     }
}

The class is annotated with @CompileStatic
When compiling that with groovy 5 (Gradle 8.14.3,  JVM: 21.0.6) i get 
the following error:.../Row.groovy: 60: [Static type checking] - Default 
method setProperty(java.lang.String, java.lang.Object) requires 
qualified super @ line 60, column 13. super.setProperty(propertyName, 
newValue)

A possible workaround is to qualify the super reference:

@Override void setProperty(String propertyName, Object newValue) {
     if (propertyNamein columnNames) {
         putAt(propertyName, newValue)
     }else {
       GroovyObject.super.setProperty(propertyName, newValue)
     }
}

Is that the recommended way to refer to the DefaultGroovyMethods 
setProperty if i cannot use super directly in groovy 5 using static 
compilation?

Regards,

Per

--------------MvQj0HQ4W5d0Cghad4dscYx8
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi,</p>
    <p>In groovy 4 i am able to do this:<br>
    </p>
    <p>I used to be able to do this: </p>
    <p>@Override <br>
      void setProperty(String propertyName, Object newValue) {<br>
          if (propertyName in columnNames) { <br>
              putAt(propertyName, newValue) <br>
          } else { <br>
              super.setProperty(propertyName, newValue) <br>
          } <br>
      }
      <br>
      <br>
      The class is annotated with @CompileStatic
      <br>
      When compiling that with groovy 5 (Gradle 8.14.3,  JVM: 21.0.6) i
      get the following error:.../Row.groovy: 60: [Static type checking]
      - Default method setProperty(java.lang.String, java.lang.Object)
      requires qualified super @ line 60, column 13.
      super.setProperty(propertyName, newValue) <br>
    </p>
    <p>A possible workaround is to qualify the super reference:<br>
    </p>
    <div style="background-color:#1e1f22;color:#bcbec4">
      <div style="background-color:#1e1f22;color:#bcbec4">
        <pre
        style="font-family:'JetBrains Mono',monospace;font-size:10.5pt;"><span
        style="color:#b3ae60;">@Override
</span><span style="color:#cf8e6d;">void </span>setProperty(String propertyName, Object newValue) {
    <span style="color:#cf8e6d;">if </span>(propertyName <span
        style="color:#cf8e6d;">in </span><span style="color:#c77dbb;">columnNames</span>) {
        putAt(propertyName, newValue)
    } <span style="color:#cf8e6d;">else </span>{
      GroovyObject.<span style="color:#cf8e6d;">super</span>.setProperty(propertyName, newValue)
    }
}</pre>
      </div>
      <pre
      style="font-family:'JetBrains Mono',monospace;font-size:10.5pt;">
</pre>
    </div>
    <p>Is that the recommended way to refer to the DefaultGroovyMethods
      setProperty if i cannot use super directly in groovy 5 using
      static compilation?</p>
    <p>Regards,</p>
    <p>Per<br>
    </p>
  </body>
</html>

--------------MvQj0HQ4W5d0Cghad4dscYx8--