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

StaticCompilationVisitor.visitForLoop sets Parameter origin type, which prevents access to original source type and location

    XMLWordPrintableJSON

Details

    Description

      StaticCompilationVisitor.visitForLoop has call to forLoop.getVariable().setOriginType(componentType). I think this call is unnecessary as the inferred type is set on the previous line. By replacing the origin type, it is no longer possible to determine the uninferred type of the parameter or the source location of the ClassNode. Additionally, I think the semantics of origin type is not being preserved by overwriting the value.

      Example:

      @CompileStatic
      def m() {
        List<String> strings = ...
        for (String s in strings) {
        }
      }
      

      In this example, the second occurrence of String is replaced in the AST by the first and so the source position of the ClassNode after "for" and before "s" is lost.

      Attachments

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h