Skip to content

fix: check generic mock implementations with type parameters - #250

Open
jihtsan wants to merge 1 commit into
matryer:mainfrom
jihtsan:codex/200-generic-ensure
Open

jihtsan wants to merge 1 commit into
matryer:mainfrom
jihtsan:codex/200-generic-ensure

Conversation

@jihtsan

@jihtsan jihtsan commented Oct 18, 2026

Copy link
Copy Markdown

Fixes #200.

Check generic mocks inside a blank generic function using the interface's declared type parameters and constraints. This preserves compile-time implementation checking without trying to instantiate constraints such as comparable or selecting a concrete type for a type set with required methods. Keep ordinary non-generic checks and -skip-ensure behavior unchanged; remove the now-unused concrete-constraint guessing code and update the affected golden files.

Validation:

  • The new regression generates and compiles mocks for comparable and dependent/method-bearing constraints. It fails on the original generator and passes here.
  • Renaming the generated Sort method makes compilation fail with "missing method Sort" when ensure is enabled, even though the blank function is never instantiated; -skip-ensure compiles the same deliberately broken implementation.
  • Go 1.26.0 and 1.27.2: go test ./... and go vet ./... pass. Go 1.26.0 go test -race ./... passes.
  • Followed CI's go install prerequisite for the vendored go-generate test; the built CLI is on PATH. Golden files were regenerated with TestMockGolden -update; ordinary/formatter golden checks pass.
  • An independent Go 1.26.6 CLI harness generates same-package and external-package mocks with imported constraint aliases, comparable, dependent parameters and generic return types. Compilation and actual mock/call-recording checks pass; breaking Store.Get is rejected only with ensure enabled.
  • golint ./... exits successfully with eight pre-existing documentation warnings in unchanged fixture files. No new warning is introduced.

Local validation ran on macOS/arm64; Linux and Windows execution remains for upstream CI.

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.

Support non-basic type constraints

1 participant