fix(mock): AnythingOfType returns unexported type to clear pkgsite deprecation (#1573)#1904
Open
luongs3 wants to merge 1 commit into
Open
fix(mock): AnythingOfType returns unexported type to clear pkgsite deprecation (#1573)#1904luongs3 wants to merge 1 commit into
luongs3 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1573.
Problem
pkgsite renders the
mock.AnythingOfTypefactory as deprecated, even though the factory itself has noDeprecated:marker. The deprecation bleeds in from the return type:AnythingOfTypereturnedAnythingOfTypeArgument, which is exported but markedDeprecated("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
AnythingOfTypefrom the deprecated exported aliasAnythingOfTypeArgumentto the underlying unexported typeanythingOfTypeArgument. Single-line change inmock/mock.go.What does NOT change
AnythingOfType(t string)is unchanged for callers.Arguments.Diffpath are unchanged.AnythingOfTypeArgumentremains exported and remains deprecated — values returned byAnythingOfTypeare still assignable to it via the pre-existing type alias (type AnythingOfTypeArgument = anythingOfTypeArgument).Tests
Test_AnythingOfType_Issue1573_ReturnsUnexportedTypewhich (a) compile-asserts the new unexported return type, (b) exercisesArguments.Diffto confirm matching behavior is preserved, and (c) verifies the alias-assignability path still works (i.e. backward compatibility).go test ./mock/...clean — no regressions.go vet ./mock/...andgofmt -lclean on touched files.