Skip to content

Commit 2afad9e

Browse files
authored
Merge pull request #218 from DirectXMan12/bug/collect-index-oor
🐛 Ensure same-line last-comment case is handled
2 parents 029712b + c5519c3 commit 2afad9e

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

pkg/markers/collect.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ func (v markerSubVisitor) Visit(node ast.Node) ast.Visitor {
290290
}
291291

292292
// skip comments on the same line as the previous node
293-
if v.lastLineCommentGroup != nil && v.lastLineCommentGroup.Pos() == v.allComments[v.commentInd].Pos() {
293+
// making sure to double-check for the case where we've gone past the end of the comments
294+
// but still have to finish up typespec-gendecl association (see below).
295+
if v.lastLineCommentGroup != nil && v.commentInd < len(v.allComments) && v.lastLineCommentGroup.Pos() == v.allComments[v.commentInd].Pos() {
294296
v.commentInd++
295297
}
296298

pkg/markers/markers_suite_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var _ = BeforeSuite(func() {
5454
foo "fmt" // +testing:pkglvl="not here import 3"
5555
5656
// +testing:pkglvl="not here import 4"
57-
)
57+
)
5858
5959
// +testing:pkglvl="here unattached"
6060
@@ -105,6 +105,15 @@ var _ = BeforeSuite(func() {
105105
106106
// +testing:typelvl="here on typedecl with no more"
107107
type Cheese struct { }
108+
109+
// ensure that we're fine if we've got an end-of-line
110+
// comment that's the last comment of the file, but
111+
// we still have a bit more to traverse (field list --> ident).
112+
// THIS MUST CONTAIN THE LAST COMMENT IN THE FILE
113+
// TODO(directxman12): split this off into its own case
114+
type private struct {
115+
bar int // not collected
116+
}
108117
`,
109118
},
110119
},

0 commit comments

Comments
 (0)