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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.4, 2.4.5
    • Fix Version/s: 2.4.6
    • Component/s: None
    • Labels:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: