Skip to content

cl: tolerate invalid receivers during syntax preload - #2226

Open
cpunion wants to merge 10 commits into
xgo-dev:mainfrom
cpunion:codex/xfail-malformed-receiver-v2-20260730
Open

cl: tolerate invalid receivers during syntax preload#2226
cpunion wants to merge 10 commits into
xgo-dev:mainfrom
cpunion:codex/xfail-malformed-receiver-v2-20260730

Conversation

@cpunion

@cpunion cpunion commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Depends on #2222.

Summary

  • make syntax preload skip only function declarations whose receiver AST cannot be converted safely, instead of panicking
  • normalize legal parenthesized, pointer, and generic receiver forms through a single checked conversion path
  • keep processing later valid declarations and their linkname directives
  • match the exact same-line recovery diagnostics for fixedbugs/issue20789.go and remove that xfail

The regression starts with the valid-but-invalid-receiver declaration func ([]int) m() {}. It also covers the review counterexamples ((*T)), (*(T)), generic value receivers, and parenthesized generic pointer receivers, so the checked path does not reject legal receiver syntax.

Validation

  • go test ./cl -run "^(TestParsePkgSyntaxSkipsInvalidReceiver|TestAstAndTypesFuncNameCoverage|TestParsePkgSyntax.*)$" -count=1
  • go test ./internal/packages ./cmd/internal/compile ./test/goroot -count=1
  • fixedbugs/issue20789.go with an empty xfail set on Go 1.24.11, 1.25.0, 1.26.0, and 1.26.5
  • all remaining Go 1.26 compile/errorcheck xfails on Go 1.26.5
  • git diff --check

No broad package parse-error gate is added; unrelated declarations and packages keep their existing preload behavior.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

Reviewed the full 8-commit diff (cl/import.go core change + test/goroot recovery-pairing harness and xfail removals). The core refactor is correct and well-guarded:

  • recvTypeNameInfo / astFuncNameOK fail safe on every non-Ident/non-simple-index receiver shape (including nil), correctly normalize parenthesized, pointer, and generic (G[P], ((*G[P]))) forms via ast.Unparen, and ParsePkgSyntax now continues on an unconvertible receiver instead of panicking.
  • The retained panic("unreachable") in recvTypeName / astFuncName is only reachable from the post-typecheck initFiles path, so it is a genuine invariant guard rather than a latent crash on malformed source.
  • The test coverage (fail-open: missing/mismatched/wrong-line/wrong-file/line-directive primaries; TestParsePkgSyntaxSkipsInvalidReceiver) is thorough, and the diagnosticPathResolver.resolve tightening is a good hardening.

No bugs, regressions, security, or performance issues found. Doc comments match final-state code. One minor maintainability nit posted inline; the remaining observations below are optional.

Optional (non-blocking)

  • test/goroot/runner_test.goparserRecoverySecondaries / parserRecoverySourceSecondaries / parserRecoverySecondaryGroups form a hand-maintained catalog of exact GOROOT source shapes and exact go/parser diagnostic spellings. This is intentional and well-commented, but the literals are version-sensitive (see the invalid use of ... Go-version difference already captured) and will silently rot on a Go bump. Consider consolidating the three functions into a single data table (primary, optional exact-source, secondary-groups) plus a note on how to regenerate/verify the golden spellings when bumping Go.
  • cl/import.go:385,426 — a one-line comment on each panic wrapper noting that the invalid-receiver path is handled by astFuncNameOK/recvTypeNameInfo and this variant asserts a checked (post-typecheck) invariant would prevent a future reader from treating the panic as dead code or a latent crash.
  • test/goroot/runner_test.go hasLineDirective — the //line branch requires start-of-line-only preceding whitespace while the /*line branch intentionally does not; this is correct per Go's spec but looks asymmetric. A one-line comment would prevent a future "fix" from breaking it.

Comment thread cl/import.go
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.94737% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cl/import.go 78.94% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@cpunion
cpunion force-pushed the codex/xfail-malformed-receiver-v2-20260730 branch from 9d4d009 to 51d67b2 Compare July 30, 2026 04:39
@cpunion

cpunion commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto the updated #2222 head after #2218 merged, then addressed the review and Codecov gaps in 51d67b23c.

The update documents the two post-typecheck invariant wrappers and adds direct counterexamples for an indexed non-identifier receiver base, an invalid array receiver, an index-list receiver, nil declarations and names, empty and nil receiver fields, invalid receiver types, and both invariant panic paths.

Validation after rebase:

  • focused cl receiver/parser tests
  • go test ./internal/packages ./cmd/internal/compile ./test/goroot -count=1
  • Go 1.26.5 fixedbugs/issue20789.go
  • git diff --check

The new CI and coverage run is in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant