From: Rob Findley Date: Fri, 12 May 2023 14:27:33 +0000 (-0400) Subject: go/types, types2: be sure to type-check wrong methods in missingMethod X-Git-Tag: go1.21rc1~549 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2ce84c3a6e14bc2720ca635cb38cac565fab0d9b;p=gostls13.git go/types, types2: be sure to type-check wrong methods in missingMethod In the case of a wrong method, we were not ensuring that it was type-checked before passing it to funcString. Formatting the missing method error message requires a fully set-up signature. Fixes #59848 Change-Id: I1467e036afbbbdd00899bfd627a945500dc709c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/494615 TryBot-Result: Gopher Robot Run-TryBot: Robert Findley Reviewed-by: Alan Donovan --- diff --git a/src/cmd/compile/internal/types2/lookup.go b/src/cmd/compile/internal/types2/lookup.go index e0b19718a1..ccf724373b 100644 --- a/src/cmd/compile/internal/types2/lookup.go +++ b/src/cmd/compile/internal/types2/lookup.go @@ -387,6 +387,10 @@ func (check *Checker) missingMethod(V, T Type, static bool, equivalent func(x, y obj, _, _ = lookupFieldOrMethodImpl(V, false, m.pkg, m.name, true /* fold case */) f, _ = obj.(*Func) if f != nil { + // This method is formatted in funcString below, so must be type-checked. + if check != nil { + check.objDecl(f, nil) + } state = wrongName } } diff --git a/src/go/types/lookup.go b/src/go/types/lookup.go index 8187cfb1a5..0ff5db74e6 100644 --- a/src/go/types/lookup.go +++ b/src/go/types/lookup.go @@ -389,6 +389,10 @@ func (check *Checker) missingMethod(V, T Type, static bool, equivalent func(x, y obj, _, _ = lookupFieldOrMethodImpl(V, false, m.pkg, m.name, true /* fold case */) f, _ = obj.(*Func) if f != nil { + // This method is formatted in funcString below, so must be type-checked. + if check != nil { + check.objDecl(f, nil) + } state = wrongName } } diff --git a/src/internal/types/testdata/fixedbugs/issue59848.go b/src/internal/types/testdata/fixedbugs/issue59848.go new file mode 100644 index 0000000000..51da7475e5 --- /dev/null +++ b/src/internal/types/testdata/fixedbugs/issue59848.go @@ -0,0 +1,10 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type T struct{} +type I interface{ M() } +var _ I = T /* ERROR "missing method M" */ {} // must not crash +func (T) m() {}