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

Plus assignment for unusual property

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.7
    • None
    • Static Type Checker
    • None

    Description

      class A {
          C plus(B b) {
              println "plus"
              new C()
          }
      }
      
      class B {}
      
      class C {}
      
      class Foo {
          A getProp() {
              println "get"
              new A()
          }
      
          void setProp(C c) {
              println "set"
          }
      }
      
      @CompileStatic
      class Main {
          static void main(String[] args) {
              def foo = new Foo()
              foo.prop += new B()
          }
      }
      

      Correctly prints without @CompileStatic:

      get
      plus
      set
      

      With @CompileStatic fails with:

      Error:(32, 9) Groovyc: 
      [Static type checking] - Cannot assign value of type B to variable of type C
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            daniilo Daniil Ovchinnikov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: