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

STC: instanceof and for-in variable type

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5.14, 3.0.8, 4.0.0-alpha-3
    • Fix Version/s: 4.0.0-beta-1, 3.0.9
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      Variation of GROOVY-6240.  Consider the following:

      @groovy.transform.TypeChecked
      void test(args) {
        if (args instanceof Map) {
          for (e in args) {
            print "$e.key $e.value" // STC errors: No such property "key/value" for Object
          }
        }
      }
      test(a:1,b:2,c:3.14)
      

      When the extra layer of the instanceof check is added, STC does not use Map type when inferring type of for-in variable "e".

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              emilles Eric Milles
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: