Skip to content

fix: avoid shadowing local types in method parameters - #248

Open
jihtsan wants to merge 2 commits into
matryer:mainfrom
jihtsan:codex/216-type-shadowing
Open

jihtsan wants to merge 2 commits into
matryer:mainfrom
jihtsan:codex/216-type-shadowing

Conversation

@jihtsan

@jihtsan jihtsan commented Oct 13, 2026 •

Copy link
Copy Markdown

What changed

Avoid generating method parameters whose names shadow same-package types used by generated call records. Initial parameter naming and renaming after discovering a later import now share the same collision checks against types, imports, existing variables, and reserved names. Every numeric suffix candidate is checked before use.

Nine regression fixtures compile actual generated mocks, covering named, pointer, slice, alias, multiple-parameter, generated-name, numeric-suffix, late-import, and combined late-import/suffix collisions.

Validation

  • Built the current moq CLI locally in /tmp/help-github-review-moq-bin for the repository's generation tests.
  • PATH=/tmp/help-github-review-moq-bin:$PATH GOTOOLCHAIN=go1.26.6 go test ./... — passed.
  • PATH=/tmp/help-github-review-moq-bin:$PATH GOTOOLCHAIN=go1.26.6 go vet ./... — passed.
  • git diff --check — passed.

Validation used Go 1.26.6, matching the repository's Go 1.26 requirement. Its dependency export decoder is incompatible with the installed Go 1.27 toolchain. The temporary executable is not part of the PR.

Closes #216.

Share type and import collision checks across initial and retroactive name allocation, and validate each numeric suffix before using it. Compile regressions for late imports and generated-name collisions. Refs matryer#216.
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.

Mock method parameter shadows unexported types

1 participant