]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: be sure to type-check wrong methods in missingMethod
authorRob Findley <rfindley@google.com>
Fri, 12 May 2023 14:27:33 +0000 (10:27 -0400)
committerRobert Findley <rfindley@google.com>
Fri, 12 May 2023 14:53:44 +0000 (14:53 +0000)
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>
src/cmd/compile/internal/types2/lookup.go
src/go/types/lookup.go
src/internal/types/testdata/fixedbugs/issue59848.go [new file with mode: 0644]

index e0b19718a154b8803422ceb9b3f60ee0803e469b..ccf724373b75428e5167beae5fd9ec17bb1bda0b 100644 (file)
@@ -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
                                        }
                                }
index 8187cfb1a5da155f95e55a6548d313adf62b07d8..0ff5db74e6262cd8a66e90d2c6f927214eab1d58 100644 (file)
@@ -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 (file)
index 0000000..51da747
--- /dev/null
@@ -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() {}