mirror of
https://github.com/golang/go
synced 2024-11-19 00:54:42 -07:00
go/types: be robust in the presence of incorrect/missing position info
Fixes go/loader test crash. TBR: adonovan Change-Id: I91dba5e001afa0ee188ccea4db904a6ce744c4d0 Reviewed-on: https://go-review.googlesource.com/11042 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
e5c3ebe4c7
commit
f9379e5b1f
@ -155,8 +155,12 @@ func (check *Checker) collectObjects() {
|
|||||||
|
|
||||||
// Use the actual source file extent rather than *ast.File extent since the
|
// Use the actual source file extent rather than *ast.File extent since the
|
||||||
// latter doesn't include comments which appear at the start or end of the file.
|
// latter doesn't include comments which appear at the start or end of the file.
|
||||||
f := check.fset.File(file.Pos())
|
// Be conservative and use the *ast.File extent if we don't have a *token.File.
|
||||||
fileScope := NewScope(check.pkg.scope, token.Pos(f.Base()), token.Pos(f.Base()+f.Size()), check.filename(fileNo))
|
pos, end := file.Pos(), file.End()
|
||||||
|
if f := check.fset.File(file.Pos()); f != nil {
|
||||||
|
pos, end = token.Pos(f.Base()), token.Pos(f.Base()+f.Size())
|
||||||
|
}
|
||||||
|
fileScope := NewScope(check.pkg.scope, pos, end, check.filename(fileNo))
|
||||||
check.recordScope(file, fileScope)
|
check.recordScope(file, fileScope)
|
||||||
|
|
||||||
for _, decl := range file.Decls {
|
for _, decl := range file.Decls {
|
||||||
|
Loading…
Reference in New Issue
Block a user