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

flow typing detects unexpected error at if-else flow

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.0-rc-2, 2.3.0, 2.4.0-beta-3
    • 5.0.0-alpha-1
    • Static Type Checker
    • None

    Description

      In groovy 2.2.0-rc-3, this code:

      class A{
      }
      class B extends A{
          void foo(){}
      }
      
      @groovy.transform.TypeChecked
      void test1(A x) {
          if (x instanceof B) {
              x.foo()
          }
      }
      
      @groovy.transform.TypeChecked
      void test2(A x) {
          if (!(x instanceof B)) {
              return
          }
          x.foo()
      }
      
      @groovy.transform.TypeChecked
      void test3(A x) {
          if (!(x instanceof B)) {
              return
          }
          else {
              x.foo()
          }
      }
      @groovy.transform.TypeChecked
      void test4(A x) {
          if (!(x instanceof B)) {
              return
          }
          assert x instanceof B
          x.foo()
      }
      
      test1(new B())
      test2(new B())
      test3(new B())
      test4(new B())
      
      

      expects all OK. but test2 and test3 results in:

      % groovy a.groovy
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /Users/uehaj/work/201311/comprehension_groovy/a.groovy: 19: [Static type checking] - Cannot find matching method A#foo(). Please check if the declared type is right and if the method exists.
      @ line 19, column 5.
      x.foo()
      ^

      /Users/uehaj/work/201311/comprehension_groovy/a.groovy: 28: [Static type checking] - Cannot find matching method A#foo(). Please check if the declared type is right and if the method exists.
      @ line 28, column 9.
      x.foo()
      ^

      2 errors

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              uehaj UEHARA Junji
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: