Skip to content

Commit 2ce84c3

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent ed3ea52 commit 2ce84c3

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/cmd/compile/internal/types2/lookup.go

+4
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ func (check *Checker) missingMethod(V, T Type, static bool, equivalent func(x, y
387387
obj, _, _ = lookupFieldOrMethodImpl(V, false, m.pkg, m.name, true /* fold case */)
388388
f, _ = obj.(*Func)
389389
if f != nil {
390+
// This method is formatted in funcString below, so must be type-checked.
391+
if check != nil {
392+
check.objDecl(f, nil)
393+
}
390394
state = wrongName
391395
}
392396
}

src/go/types/lookup.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
type T struct{}
8+
type I interface{ M() }
9+
var _ I = T /* ERROR "missing method M" */ {} // must not crash
10+
func (T) m() {}

0 commit comments

Comments
 (0)