cl: preserve diagnostics for invalid method receivers - #2417
Conversation
There was a problem hiding this comment.
Review: nonlocal method receiver diagnostic
Clean, well-scoped refactor. Converting recvTypeName and astFuncName from panic-on-invalid to returning an ok boolean is the right call — it lets the type checker surface the real diagnostic (e.g. func (b *bufio.Reader) Buffered()) instead of the compiler dying with an internal panic. Pointer handling is correctly consolidated into recvTypeName, pointer-to-pointer is properly rejected, and all three call sites (initFiles, ParsePkgSyntaxWithOptions, compileFuncDecl) check ok and skip cleanly.
Reviewed across four dimensions:
- Correctness/quality — recursion covers
Ident/IndexExpr/IndexListExpr/ParenExpr/StarExpr; nested*(*T)correctly rejected. Good. - Performance — no regression; runs once per decl, bounded recursion, no extra allocations.
- Security — no unbounded-recursion/DoS surface; ASTs come from
go/parserwhich enforces its own nesting limit. Change is a net panic-surface improvement (fail-closed). - Documentation — new doc comments accurately describe the ok-boolean behavior; removal of the
// TODO: support generic typeis justified since the new code handlesIndexExpr/IndexListExpr.
Two minor, non-blocking notes inline. No blocking issues found.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
LLGo baseline benchmarks
Program measurements
Core language and compiler benchmarks
Compared with |
Summary
Behavior
Before this change, compiling fixedbugs/issue5089.go panics in cl.recvTypeName while preloading the *bufio.Reader method declaration. After this change, metadata collection skips that invalid declaration and the compiler reports:
This fixes 1 Go 1.26 GOROOT compatibility case. It also addresses the receiver-AST crash behind the issue5089 xfail proposed in #2265; if #2265 lands first, that entry should be removed when this PR is rebased.
Validation
Xfail history
This PR intentionally has no
test/goroot/xfail.yamldeletion forfixedbugs/issue5089.go: the entry was added by3f3090f71and then removed from main by4da2efa8a, so it is absent from this PR base (6fe8babd4). Commit15c415828restores the entry on the separate, unmerged #2265 line of work and is not an ancestor of this PR. If that commit is integrated before this fix, its stale issue5089 entry must be dropped while rebasing. The Go 1.26 errorcheck case also passes with an empty xfail configuration after this fix.