From ee0cf325b1acdf3cbacb153fc7a6e353c3146e3d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 12 Jun 2015 15:56:23 -0700 Subject: [PATCH] go/types: provide full source file extent to file scope Change-Id: Ib3472ab9e6b5bae0b03474ea57857fde1afbd43a Reviewed-on: https://go-review.googlesource.com/10995 Reviewed-by: Alan Donovan --- go/types/eval_test.go | 4 ++++ go/types/resolver.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/go/types/eval_test.go b/go/types/eval_test.go index e0144866762..b68b244f958 100644 --- a/go/types/eval_test.go +++ b/go/types/eval_test.go @@ -144,6 +144,10 @@ func TestEvalPos(t *testing.T) { type FT /* FT => , p.FT */ interface{} } `, + ` + package p + /* T => , p.T */ + `, } fset := token.NewFileSet() diff --git a/go/types/resolver.go b/go/types/resolver.go index e74c3c65117..6b16df3d2ae 100644 --- a/go/types/resolver.go +++ b/go/types/resolver.go @@ -153,7 +153,10 @@ func (check *Checker) collectObjects() { // but there is no corresponding package object. check.recordDef(file.Name, nil) - fileScope := NewScope(check.pkg.scope, file.Pos(), file.End(), check.filename(fileNo)) + // Use the actual source file extent rather than *ast.File extent since the + // latter doesn't include comments which appear at the end of the file. + f := check.fset.File(file.Pos()) + fileScope := NewScope(check.pkg.scope, token.Pos(f.Base()), token.Pos(f.Base()+f.Size()), check.filename(fileNo)) check.recordScope(file, fileScope) for _, decl := range file.Decls {