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

@CompileStatic transform gives unexpected result for default constructor

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.7, 2.4.0-rc-1
    • Fix Version/s: 2.4.5
    • Component/s: Static compilation
    • Labels:
      None

      Description

      The following snippet reproduces a type checking error

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Test {
          private long timestamp
          
          Date getTimestamp() {
              return timestamp ? new Date(timestamp) : null
          }
          
          void setTimestamp (Date timestamp) {
              this.timestamp = timestamp.time
          }
          
          def main() {
              new Test(timestamp: new Date())
          }
      }
      
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 16: [Static type checking] - Cannot assign value of type java.util.Date to variable of type long
       @ line 16, column 27.
                 new Test(timestamp: new Date())
                                   ^
      
      1 error
      

      This is quite unexpected it should use the type of the getter and setter for the validation since they are used later on to assign the value and not the type of the underlying field.

        Attachments

          Activity

            People

            • Assignee:
              melix Cédric Champeau
              Reporter:
              damokles Leonard Brünings
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: