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

Flow typing does not work when && is combinded with instanceof

    XMLWordPrintableJSON

Details

    Description

      I have the following Groovy program.

      @groovy.transform.TypeChecked
      class Test {
        public void foo(Foo x) {
          ((true && x instanceof Bar)) ? new Bar[]{x} : null
        }
      }
      
      class Foo {}
      
      class Bar extends Foo {}
      

      Actual Behavior

      The program does not compile, and I get the following error.

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Test.groovy: 4: [Static type checking] - Cannot convert from Foo to Bar
       @ line 4, column 46.
          instanceof Bar)) ? new Bar[]{x} : null
                                       ^
      
      1 error
      

      Expected Behavior

      Compile successfully.

      Comment

      This should be a regression bug because it works with 3.0.8 and 4.0.0-alpha-3.

      Affected Version

      This programs have been tested with the compiler from the master (commit: 8ea882a587ce3183c95ea1bc19dfc44367dc292e).

      Attachments

        Activity

          People

            emilles Eric Milles
            schaliasos Stefanos Chaliasos
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: