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

ASTTest annotation has runtime retention and transform removes required member from AST

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0.0-alpha-1
    • Component/s: None
    • Labels:

      Description

      Consider the following:

      import groovy.transform.*
      import org.codehaus.groovy.ast.*
      import static org.codehaus.groovy.transform.stc.StaticTypesMarker.*
      
      class C {
        void m() {
          def that = this;
          { ->
            @ASTTest(phase=INSTRUCTION_SELECTION, value={
              ClassNode type = node.getNodeMetaData(INFERRED_TYPE)
              assert type?.name == 'C'
            })
            def ref = getThisObject()
            assert ref == that
          }()
        }
      }
      

      This is a typical use of @ASTTest. When compiled, the test annotation is retained in the class file, which is unnecessary. When the transform class runs, it removes the "value" member from the AST, which is causing compiler errors down the line when ExtendedVerifier runs AnnotationVisitor. Also, the variable scope of the test closure is still connected to the class and module, so code completion is making proposals for class members which will not be there at run-time.

      This was originally investigated from the IDE side (see linked issue).

      https://user-images.githubusercontent.com/18193802/90964420-fd51c800-e485-11ea-8349-c0f89e04561a.png

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emilles Eric Milles
                Reporter:
                emilles Eric Milles
              • Votes:
                0 Vote for this issue
                Watchers:
                2 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 - 1h 10m
                  1h 10m