cmd/internal/obj: print error on duplicate symbol definitions

When compiling a package, when there are duplicated symbols
(probably due to a bug in the compiler), we try to print the
source locations of the two definitions. However, if one has its
Func().Text unset, it panics. Guard it with a nil check, so at
least it can print the function name.

Change-Id: I7a851970edc71dc2c8c9d694174bac42ea9c75d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/775623
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Bypass: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Cherry Mui 2026-05-08 16:02:27 -04:00
parent e49b53439d
commit 55ff407d4f

View file

@ -183,7 +183,11 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int, start src.XPos) {
return
}
if s.Func() != nil {
ctxt.Diag("%s: symbol %s redeclared\n\t%s: other declaration of symbol %s", ctxt.PosTable.Pos(start), s.Name, ctxt.PosTable.Pos(s.Func().Text.Pos), s.Name)
otherPos := src.NoPos
if s.Func().Text != nil {
otherPos = ctxt.PosTable.Pos(s.Func().Text.Pos)
}
ctxt.Diag("%s: symbol %s redeclared\n\t%s: other declaration of symbol %s", ctxt.PosTable.Pos(start), s.Name, otherPos, s.Name)
return
}
s.NewFuncInfo()