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

@CompileStatic and the method with(Closure) seem to determine wrong type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.4, 2.4.5
    • 2.4.6
    • None
    • None

    Description

      In the code below. When refer to time without the "it" prefix. The compiler get type of "time" wrongly. "time" is Date but it determined as long.

      @CompileStatic
      class GMain {
          static void main(String[] args) {
              Calendar.instance.with {
                  println time.class<span class="code-comment">//This print java.util.Date which is OK
                  Date d1 = time//This line failed to compile with error Groovyc: [Static type checking] - Cannot assign value of type long to variable of type java.util.Date
                  Date d2 = it.time//This line is OK
              }
          }
      }
      

      Attachments

        Activity

          People

            shils Shil Sinha
            trapongx Teerapong Suksuwan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: