From 374bd6a3ac7a201cfb37230942fedaa0451e4de6 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 15 May 2023 13:42:13 -0400 Subject: [PATCH] cmd/compile/internal/typecheck: remove base.Errorf from Assignop The documentation for Assignop specifies that if the assignment is not valid, the reason for the failure is returned via a reason string without failing the build. A few cases in Assignop1 -> implements -> ifacelookdot directly call base.Errorf rather than plumbing through the reason string as they should. Drop these calls. Since error messages are mostly unreachable here (it only applies to generated code), don't maintain them and allow them to just fallthrough to the generic "missing method" message. This is important for PGO specialization, which opportunistically checks if candidate interface call targets implement the interface. Many of these will fail, which should not break the build. For #59959. Change-Id: I1891ca0ebebc1c1f51a0d0285035bbe8753036bc Reviewed-on: https://go-review.googlesource.com/c/go/+/494959 Run-TryBot: Michael Pratt TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Reviewed-by: Cherry Mui Auto-Submit: Michael Pratt --- src/cmd/compile/internal/typecheck/subr.go | 26 +++++++--------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/cmd/compile/internal/typecheck/subr.go b/src/cmd/compile/internal/typecheck/subr.go index ad8e801d67..557d993f1c 100644 --- a/src/cmd/compile/internal/typecheck/subr.go +++ b/src/cmd/compile/internal/typecheck/subr.go @@ -691,32 +691,22 @@ func expand1(t *types.Type, top bool) { t.SetRecur(false) } -func ifacelookdot(s *types.Sym, t *types.Type, ignorecase bool) (m *types.Field, followptr bool) { +func ifacelookdot(s *types.Sym, t *types.Type, ignorecase bool) *types.Field { if t == nil { - return nil, false + return nil } - path, ambig := dotpath(s, t, &m, ignorecase) + var m *types.Field + path, _ := dotpath(s, t, &m, ignorecase) if path == nil { - if ambig { - base.Errorf("%v.%v is ambiguous", t, s) - } - return nil, false - } - - for _, d := range path { - if d.field.Type.IsPtr() { - followptr = true - break - } + return nil } if !m.IsMethod() { - base.Errorf("%v.%v is a field, not a method", t, s) - return nil, followptr + return nil } - return m, followptr + return m } // implements reports whether t implements the interface iface. t can be @@ -768,7 +758,7 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool } if i == len(tms) { *m = im - *samename, _ = ifacelookdot(im.Sym, t, true) + *samename = ifacelookdot(im.Sym, t, true) *ptr = 0 return false } -- 2.50.0