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

STC changes the inferred type of variable in the presence of flow typing

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-1
    • Static Type Checker
    • None

    Description

      This may be related to GROOVY-10294.

      I have the following program

      interface A {
        void a();
      }
      
      class Test {
      
        void test_closure() {
          def a = (A) null;
          def x = { ->
            a = null;
          }
      
          a.a();
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 15: [Static type checking] - A closure shared variable [a] has been assigned with various types and the method [a()] does not exist in the lowest upper bound of those types: [java.lang.Object]. In general, this is a bad practice (variable reuse) because the compiler cannot determine safely what is the type of the variable at the moment of the call in a multithreaded context.
       @ line 15, column 5.
             a.a();
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Tested against master (https://github.com/apache/groovy/commit/0ff632514f9e06b8cea96f2e70749b3da3bc6dbb).

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: