From b477088e49d492c9b14f9448c7f4aac7d77a4174 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sun, 9 Mar 2025 12:47:04 +0800 Subject: [PATCH] gop/ast: File.End --- ast/ast_gop.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ast/ast_gop.go b/ast/ast_gop.go index 4800073c9..0f0791ff3 100644 --- a/ast/ast_gop.go +++ b/ast/ast_gop.go @@ -494,14 +494,21 @@ func (f *File) Pos() token.Pos { // End returns position of first character immediately after the node. func (f *File) End() token.Pos { + if f.ShadowEntry != nil { // has shadow entry + return f.ShadowEntry.End() + } for n := len(f.Decls) - 1; n >= 0; n-- { d := f.Decls[n] - if fn, ok := d.(*FuncDecl); ok && fn.Shadow && fn != f.ShadowEntry { + if fn, ok := d.(*FuncDecl); ok && fn.Shadow { + // skip shadow functions like Classfname (see cl.astFnClassfname) continue } return d.End() } - return f.Name.End() + if f.Package != token.NoPos { // has package clause + return f.Name.End() + } + return f.Name.Pos() } // -----------------------------------------------------------------------------