Skip to content

Commit ca1eba0

Browse files
authored
fix(go): return nil instead of panic when AST node has invalid position (#197)
* fix(go): return nil instead of panic when AST node has invalid position When parsing files with compilation errors, AST nodes can have End offset smaller than Pos offset, causing slice bounds out of range panic.
1 parent f7385d6 commit ca1eba0

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

.github/workflows/go-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
components: rust-analyzer
4343

4444
- name: Install gopls
45-
run: go install golang.org/x/tools/gopls@latest
45+
run: go install golang.org/x/tools/gopls@v0.16.2
4646

4747
- name: Run all tests
4848
run: go test ./lang/... -skip '${{ env.SKIPPED_TESTS }}'

lang/golang/parser/ctx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func GetRawContent(fset *token.FileSet, file []byte, node ast.Node, collectComme
257257
funcName = fn.Name.Name
258258
}
259259
fmt.Fprintf(os.Stderr, "end < begin, file: %s, function: %s, possibly because file compilation failed\n", pos.Filename, funcName)
260+
return nil
260261
}
261262
doc.Write(file[pos.Offset:endPos.Offset])
262263
return doc.Bytes()

0 commit comments

Comments
 (0)