From 3747f8666e39499636497f58afdcb46d632da8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Ph=C3=BAc=20L=C6=B0=C6=A1ng?= Date: Thu, 28 May 2026 08:16:14 +0000 Subject: [PATCH] fix(mock): AnythingOfType returns unexported type to clear pkgsite deprecation (#1573) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) Signed-off-by: Nguyễn Phúc Lương --- mock/mock.go | 2 +- mock/mock_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mock/mock.go b/mock/mock.go index a13c37f3b..ea11365be 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -816,7 +816,7 @@ type anythingOfTypeArgument string // For example: // // args.Assert(t, AnythingOfType("string"), AnythingOfType("int")) -func AnythingOfType(t string) AnythingOfTypeArgument { +func AnythingOfType(t string) anythingOfTypeArgument { return anythingOfTypeArgument(t) } diff --git a/mock/mock_test.go b/mock/mock_test.go index 3dc9e0b1e..557565c69 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -2467,3 +2467,27 @@ func TestIssue1227AssertExpectationsForObjectsWithMock(t *testing.T) { AssertExpectationsForObjects(mockT, Mock{}) assert.Equal(t, 1, mockT.errorfCount) } + +// Test_AnythingOfType_Issue1573_ReturnsUnexportedType pins the return type of +// AnythingOfType to the unexported anythingOfTypeArgument. This is a regression +// guard for issue #1573: when AnythingOfType returned the publicly-exported +// (and deprecated) AnythingOfTypeArgument alias, pkgsite rendered the factory +// itself as deprecated. Returning the unexported type clears the deprecation +// marker without changing observable behavior for callers. +func Test_AnythingOfType_Issue1573_ReturnsUnexportedType(t *testing.T) { + t.Parallel() + + // Compile-time assignability check: result must satisfy the unexported type. + var got anythingOfTypeArgument = AnythingOfType("string") + + // Behavior unchanged: still matches via the Diff path used by the matcher. + args := Arguments([]interface{}{got}) + _, count := args.Diff([]interface{}{"hello"}) + assert.Equal(t, 0, count) + + // And still backwards-compatible with the deprecated exported alias: the + // value is assignable to AnythingOfTypeArgument because they share an + // underlying type via the existing type alias. + var alias AnythingOfTypeArgument = got + _ = alias +}