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

Static compiler infers wrong type for implicitly shared variables

    XMLWordPrintableJSON

Details

    Description

      Consider the following code

      class A {}
      class B extends A{ def b() {}}
      class C extends A{}
      
      @CompileStatic
      static foo() {
        def x = new B()
        ({ x = new C() })()
        def z = x
        z.b()
      }
      

      Here type of z in the last line of the method is deduced to be B. Attempt to execute z.b() leads to cast exception, which is unexpected under static compilation.

      Attachments

        Activity

          People

            emilles Eric Milles
            knisht Konstantin Nisht
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: