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

Incorrect inferred type in instanceof check of array

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.10, 2.4.1
    • 2.3.11, 2.4.2
    • Static Type Checker
    • None

    Description

      The following code fails with a weird type checking error:

      import groovy.transform.TypeChecked
      
      int len(byte[] arr) { arr.length }
      @TypeChecked
      def foo(arg) {
         if (arg instanceof byte[]) {
            len(arg)
         }
      }
      foo(new byte[3])
      

      Error:

      [Static type checking] - Cannot call ConsoleScript0#len(byte[]) with arguments [<UnionTypejava.lang.Object+[B>]
      at line: 7, column: 7

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              melix Cédric Champeau
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: