[tools] refactor/satisfy: fix panic on interface literals

0 views
Skip to first unread message

Madeline Kalil (Gerrit)

unread,
Feb 24, 2026, 12:06:55 PM (16 hours ago) Feb 24
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Alan Donovan, Mark Freeman, golang-co...@googlegroups.com

Madeline Kalil submitted the change with unreviewed changes

Unreviewed changes

3 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: refactor/satisfy/find.go
Insertions: 4, Deletions: 5.

@@ -395,11 +395,10 @@
f.expr(e.X)

case *ast.SelectorExpr:
- if _, ok := f.info.Selections[e]; ok {
- if tv, ok := f.info.Types[e.X]; ok && tv.IsType() {
- // If e.X is a type (e.g., e is interface{ m() }.m), don't visit it.
- } else {
- f.expr(e.X) // selection
+ if seln, ok := f.info.Selections[e]; ok {
+ // If e.X is a type (e.g., e is interface{ m() }.m), don't visit it.
+ if seln.Kind() != types.MethodExpr {
+ f.expr(e.X)
}
} else {
return f.info.Uses[e.Sel].Type() // qualified identifier
```

Change information

Commit message:
refactor/satisfy: fix panic on interface literals

The inspection of the AST in Find() results in a panic
when you have a method expression of an anonymous
interface, because it does not expect an
interface type literal to appear as an expression.

However, this is valid Go code:

// panics on interface{ m() } after visiting e.X in the SelectorExpr e
var _ = interface{ m() }.m

During the AST traversal, if we encounter a SelectorExpr e
where e.X is a type (like interface{Baz()}), we don't need
to visit e.X.

This also fixes a panic in the printf analyzer,
which uses Find to get interface/implementation relations.
Fixes golang/go#77625
Change-Id: I431b70e2c7e3cc9b2db655e99fdb25c223a1a082
Reviewed-by: Mark Freeman <markf...@google.com>
Reviewed-by: Alan Donovan <adon...@google.com>
Files:
  • M refactor/satisfy/find.go
  • M refactor/satisfy/find_test.go
Change size: S
Delta: 2 files changed, 8 insertions(+), 2 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Alan Donovan, +2 by Mark Freeman
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I431b70e2c7e3cc9b2db655e99fdb25c223a1a082
Gerrit-Change-Number: 746701
Gerrit-PatchSet: 6
Gerrit-Owner: Madeline Kalil <mka...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
Gerrit-Reviewer: Mark Freeman <markf...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages