diff options
| author | Rob Findley <rfindley@google.com> | 2023-05-12 10:27:33 -0400 |
|---|---|---|
| committer | Robert Findley <rfindley@google.com> | 2023-05-12 14:53:44 +0000 |
| commit | 2ce84c3a6e14bc2720ca635cb38cac565fab0d9b (patch) | |
| tree | 5b6bd536c535b0a16657de7af4c1fe313c3ed5a8 /src | |
| parent | ed3ea520812e314b2948ae39267105fa517bd9fe (diff) | |
| download | go-2ce84c3a6e14bc2720ca635cb38cac565fab0d9b.tar.xz | |
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 <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/types2/lookup.go | 4 | ||||
| -rw-r--r-- | src/go/types/lookup.go | 4 | ||||
| -rw-r--r-- | src/internal/types/testdata/fixedbugs/issue59848.go | 10 |
3 files changed, 18 insertions, 0 deletions
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() {} |
