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

The if(instanceof) block is not inferring type in a Closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.4
    • 2.1.0-beta-1
    • Static compilation
    • None

    Description

      I expect these classes to be compiled but it won't.

      import groovy.transform.*
      
      @CompileStatic
      class Greeting implements Serializable {
          String who
      }
      
      import groovy.transform.*
      
      @CompileStatic
      class GreetingActor {
      
        def receive = {
          if(it instanceof Greeting) {
              println "Hello ${it.who}"
          }
        }
      
      }
      

      The type of variable "it" in the Closure receive should be inferred as type Greeting. To reproduce call

      $ groovyc Greeting.groovy GreetingActor.groovy

      Thank you.

      Attachments

        Activity

          People

            melix Cédric Champeau
            chanwit Chanwit Kaewkasi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: