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

Variable type is not updated in operator assignment

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.5.8
    • Fix Version/s: None
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      class A { B plus(x) { new B() } }
      class B { def foo() {42} }
      
      @groovy.transform.CompileStatic
      def cs() {
          def var
          var = new A()
          var = var + 1
          var.foo()
      }
      
      assert cs() == 42
      
      @groovy.transform.CompileStatic
      def cs2() {
          def var
          var = new A()
          var += 1 
          var.foo() // Cannot find matching method A#foo()
      }
      
      assert cs2() == 42
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: