[tools] gopls/internal/golang: Implementations: reject generic methods (local)

1 view
Skip to first unread message

Alan Donovan (Gerrit)

unread,
Jun 9, 2026, 1:06:41 PM (16 hours ago) Jun 9
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Alan Donovan has uploaded the change for review

Commit message

gopls/internal/golang: Implementations: reject generic methods (local)

This CL causes the local (same-package) algorithm for Implementations
to reject generic methods in either argument of implements(Tx, Ty).

+ test

(This is a defensive change from first principles; the test was
passing even before the code change.)

For golang/go#77549
Change-Id: I7253879343f658bb118a711d96a61893343be137

Change diff

diff --git a/gopls/internal/golang/implementation.go b/gopls/internal/golang/implementation.go
index 49963e5..220ba0a 100644
--- a/gopls/internal/golang/implementation.go
+++ b/gopls/internal/golang/implementation.go
@@ -548,11 +548,23 @@
for method := range ymset.Methods() {
ym := method.Obj().(*types.Func)

+ // Ignore generic methods, for safety.
+ // This is probably unnecessary since they cannot
+ // appear in a true interface type.
+ // (They can appear in a constraint interface type,
+ // but we shouldn't be called in that case.)
+ if ym.Signature().TypeParams().Len() > 0 {
+ continue
+ }
+
xobj, _, _ := types.LookupFieldOrMethod(x, false, ym.Pkg(), ym.Name())
xm, ok := xobj.(*types.Func)
if !ok {
return false // x lacks a method of y
}
+ if xm.Signature().TypeParams().Len() > 0 {
+ return false // generic methods do not satisfy interface methods
+ }
if !unify(xm.Signature(), ym.Signature(), nil) {
return false // signatures do not match
}
diff --git a/gopls/internal/test/marker/testdata/implementation/genericmethods.txt b/gopls/internal/test/marker/testdata/implementation/genericmethods.txt
index 28f9dca..e3dd66c 100644
--- a/gopls/internal/test/marker/testdata/implementation/genericmethods.txt
+++ b/gopls/internal/test/marker/testdata/implementation/genericmethods.txt
@@ -1,6 +1,9 @@
Test of 'implementation' query on generic methods, which don't
participate in interface satisfaction.

+Test same-package and cross-package cases,
+since they use different logic.
+
-- flags --
-min_go=go1.27

@@ -15,6 +18,10 @@

func (C) F[T any](T) {} //@ implementation("F")

+type I interface {
+ F(int)
+}
+
-- b/a.go --
package a

Change information

Files:
  • M gopls/internal/golang/implementation.go
  • M gopls/internal/test/marker/testdata/implementation/genericmethods.txt
Change size: S
Delta: 2 files changed, 19 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I7253879343f658bb118a711d96a61893343be137
Gerrit-Change-Number: 788881
Gerrit-PatchSet: 1
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Jun 9, 2026, 1:07:04 PM (16 hours ago) Jun 9
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Alan Donovan uploaded new patchset

Alan Donovan uploaded patch set #2 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I7253879343f658bb118a711d96a61893343be137
Gerrit-Change-Number: 788881
Gerrit-PatchSet: 2
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Jun 9, 2026, 1:11:56 PM (16 hours ago) Jun 9
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Alan Donovan uploaded new patchset

Alan Donovan uploaded patch set #3 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I7253879343f658bb118a711d96a61893343be137
Gerrit-Change-Number: 788881
Gerrit-PatchSet: 3
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Jun 9, 2026, 11:35:56 PM (6 hours ago) Jun 9
to goph...@pubsubhelper.golang.org, Mark Freeman, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from Mark Freeman

Alan Donovan voted

Auto-Submit+1
Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Mark Freeman
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: I7253879343f658bb118a711d96a61893343be137
    Gerrit-Change-Number: 788881
    Gerrit-PatchSet: 3
    Gerrit-Owner: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Mark Freeman <markf...@google.com>
    Gerrit-Attention: Mark Freeman <markf...@google.com>
    Gerrit-Comment-Date: Wed, 10 Jun 2026 03:35:51 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages