Skip to content

Commit f9379e5

Browse files
committed
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 <[email protected]>
1 parent e5c3ebe commit f9379e5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

go/types/resolver.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ func (check *Checker) collectObjects() {
155155

156156
// Use the actual source file extent rather than *ast.File extent since the
157157
// latter doesn't include comments which appear at the start or end of the file.
158-
f := check.fset.File(file.Pos())
159-
fileScope := NewScope(check.pkg.scope, token.Pos(f.Base()), token.Pos(f.Base()+f.Size()), check.filename(fileNo))
158+
// Be conservative and use the *ast.File extent if we don't have a *token.File.
159+
pos, end := file.Pos(), file.End()
160+
if f := check.fset.File(file.Pos()); f != nil {
161+
pos, end = token.Pos(f.Base()), token.Pos(f.Base()+f.Size())
162+
}
163+
fileScope := NewScope(check.pkg.scope, pos, end, check.filename(fileNo))
160164
check.recordScope(file, fileScope)
161165

162166
for _, decl := range file.Decls {

0 commit comments

Comments
 (0)