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

Incorrect line numbers for Closure classes in AstNode

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.10
    • 3.0.11, 4.0.2
    • None
    • None

    Description

      The line number recorded in the compiled class for Closure is incorrect in certain circumstances.

       

      1. void doThing(Closure c) {
      2.   c.class()
      3. }
      4.
      5. void go() {
      6.   doThing { // This is a comment
      7.     // And there is no body
      8.   }
      9. }

      When grabbing the lineNumber (using javassist and loading the doCall method from the CtClass for the Closure), it is reported as line 8, where in Groovy 2.5.x it was reported as line 6. Removing the comments but leaving just a new line between the } and { (an empty block) has the same result.

      The expected outcome here should be line 6 as that's the start of the closure.

      If you modify the closure like so:

       

      1. void doThing(Closure c) {
      2.   c.class()
      3. }
      4.
      5. void go() {
      6.   doThing { // This is a comment
      7.     println "hi"
      8.   }
      9. }

      The line is reported as line 7. This is also incorrect as that would be the BlockStatement inside the Closure.

      Trying to debug the parser, I ended up in GroovyParse.blockStatementOpts which appears to be setting the startLine value incorrectly (The below screen shot is from compilation of a similar class where a closure contains only comments). Notice that start is marked as a line number after end which can't really be true.

       

       

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            paulk Paul King
            johnrengelman John Engelman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment