]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/typecheck: remove base.Errorf from Assignop
authorMichael Pratt <mpratt@google.com>
Mon, 15 May 2023 17:42:13 +0000 (13:42 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 22 May 2023 15:07:01 +0000 (15:07 +0000)
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 <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>

src/cmd/compile/internal/typecheck/subr.go

index ad8e801d679d6ac3e32aeac14044063073856439..557d993f1c1a27024f277270abe02ee53c934648 100644 (file)
@@ -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
                }