Skip to content

Commit 55ff407

Browse files
committed
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>
1 parent e49b534 commit 55ff407

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/cmd/internal/obj/plist.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int, start src.XPos) {
183183
return
184184
}
185185
if s.Func() != nil {
186-
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)
186+
otherPos := src.NoPos
187+
if s.Func().Text != nil {
188+
otherPos = ctxt.PosTable.Pos(s.Func().Text.Pos)
189+
}
190+
ctxt.Diag("%s: symbol %s redeclared\n\t%s: other declaration of symbol %s", ctxt.PosTable.Pos(start), s.Name, otherPos, s.Name)
187191
return
188192
}
189193
s.NewFuncInfo()

0 commit comments

Comments
 (0)