Skip to content

fix(mock): AnythingOfType returns unexported type to clear pkgsite deprecation (#1573)#1904

Open
luongs3 wants to merge 1 commit into
stretchr:masterfrom
luongs3:fix/1573-anythingoftype-pkgsite
Open

fix(mock): AnythingOfType returns unexported type to clear pkgsite deprecation (#1573)#1904
luongs3 wants to merge 1 commit into
stretchr:masterfrom
luongs3:fix/1573-anythingoftype-pkgsite

Conversation

@luongs3
Copy link
Copy Markdown

@luongs3 luongs3 commented May 28, 2026

Fixes #1573.

Problem

pkgsite renders the mock.AnythingOfType factory as deprecated, even though the factory itself has no Deprecated: marker. The deprecation bleeds in from the return type: AnythingOfType returned AnythingOfTypeArgument, which is exported but marked Deprecated ("an implementation detail that must not be used"). pkgsite propagates deprecation from referenced exported types to their constructors, so the factory inherits the marker.

Fix

Change the return type of AnythingOfType from the deprecated exported alias AnythingOfTypeArgument to the underlying unexported type anythingOfTypeArgument. Single-line change in mock/mock.go.

What does NOT change

  • Function signature AnythingOfType(t string) is unchanged for callers.
  • Runtime behavior, matching semantics, and the Arguments.Diff path are unchanged.
  • AnythingOfTypeArgument remains exported and remains deprecated — values returned by AnythingOfType are still assignable to it via the pre-existing type alias (type AnythingOfTypeArgument = anythingOfTypeArgument).
  • No callsite has to be updated. The exported alias name continues to work in user code that already references it.

Tests

  • Added Test_AnythingOfType_Issue1573_ReturnsUnexportedType which (a) compile-asserts the new unexported return type, (b) exercises Arguments.Diff to confirm matching behavior is preserved, and (c) verifies the alias-assignability path still works (i.e. backward compatibility).
  • Full go test ./mock/... clean — no regressions.
  • go vet ./mock/... and gofmt -l clean on touched files.

…precation (stretchr#1573)

Problem:
pkgsite renders the mock.AnythingOfType factory as deprecated, even though
the factory itself has no Deprecated marker. The deprecation bleeds in from
the return type: AnythingOfType returned AnythingOfTypeArgument, which is
exported but marked Deprecated as 'an implementation detail that must not
be used.' pkgsite propagates deprecation from referenced types to their
constructors, so the factory inherits the marker.

Fix:
Change the return type of AnythingOfType from the deprecated exported alias
AnythingOfTypeArgument to the underlying unexported type
anythingOfTypeArgument. The exported alias is kept for backward
compatibility (it remains a type alias of the unexported type, so existing
code that names AnythingOfTypeArgument still compiles).

What does NOT change:
- The function signature 'AnythingOfType(t string)' is unchanged.
- The runtime behavior, matching semantics, and Arguments.Diff path are
  unchanged.
- AnythingOfTypeArgument remains exported and remains deprecated; values
  returned by AnythingOfType remain assignable to it via the existing alias.

Test:
- Added Test_AnythingOfType_Issue1573_ReturnsUnexportedType which compile-
  asserts the new return type, exercises the Diff matcher to confirm
  behavior is preserved, and verifies the alias-assignability path still
  works.
- 'go test ./mock/...' clean (no regressions).
- 'go vet ./mock/...' and 'gofmt -l' clean on touched files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Nguyễn Phúc Lương <phucluong2194@gmail.com>
@dolmen dolmen added pkg-mock Any issues related to Mock mock.ArgumentMatcher About matching arguments in mock labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mock.ArgumentMatcher About matching arguments in mock pkg-mock Any issues related to Mock

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mock: AnythingOfType is marked deprecated on pkgsite

2 participants