Feat/generic forward methods - #156
Merged
Merged
Conversation
go1.27 accepts type parameters on methods, so the 55 generic assertions become methods of the Assertions type: a.EqualT(expected, actual) next to assert.EqualT(t, expected, actual). Eventually, Never, Consistently and EventuallyWith gain a method for the first time; being generic without a T suffix, they had none at all. The methods land in assert/assert_forward_go127.go and require/require_forward_go127.go, guarded by //go:build go1.27. A go1.25 or go1.26 build drops those files and keeps the package-level functions. Codegen: - Function.ForwardGoBuild returns max(source guard, go1.27) for a generic function, so ErrorAsType and NotErrorAsType (guarded go1.26) join the go1.27 file and a future go1.28 generic assertion would get its own; - Generate runs a second partition loop over ForwardBuildVariants, and selectVariant takes the partitioning key, SourceGoBuild or ForwardGoBuild; - the forward templates render both partitions from one body, since GenericName and GenericCallName fall back to Name for a plain function. Doc site: - method rows for generic assertions carry a goversion "go1.27" badge; - every assertion now counts 4 variants per package, where generics counted 2: package_variants 446 -> 556, total API surface 902 -> 1122. The go.work toolchain floor moves to go1.27.0. TestToolchainFloorCoversGuards only scans internal/assertions, so it does not enforce this guard: codegen emits it, and the go.work comment records why the floor must cover it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
The per-function tabs rendered by doc_page.md.gotmpl listed signatures the generated packages do not have: - every require row carried a bool return, though a require assertion calls FailNow instead of returning: `require.Equal(t T, ...) bool`; - the method formatted row dropped the return for assert, and spelled its variadic `args ..any`; - helpers picked up formatted and method rows, so common.md linked to require.CallerInfof and (*Assertions).ObjectsAreEqual, neither of which is generated: assertion_helpers.gotmpl emits the package-level function alone, with no t T parameter to format against. The template now blanks the return for a require assertion, keeps it for a require helper such as CallerInfo, and renders the three variant rows only for assertions. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #156 +/- ##
==========================================
+ Coverage 93.35% 93.65% +0.30%
==========================================
Files 103 106 +3
Lines 12875 13793 +918
==========================================
+ Hits 12019 12918 +899
- Misses 849 868 +19
Partials 7 7 ☔ View full report in Codecov by Harness. |
x/tools/imports formats every file the generator writes with the go/parser of the toolchain running codegen. Before go1.27 that parser rejects a generic method with "method must have no type parameters", whatever //go:build line the generated file carries, so a run that emits the go1.27 forward files cannot complete and the oldstable CI leg failed on three tests. - forward_generics_test.go carries //go:build go1.27: every test in it drives the generator over a generic assertion; - TestExecute, which runs the whole pipeline over internal/assertions, skips when a probe parse of a generic method fails. The rest of main_test.go still runs, TestExecuteMultiplePackages included: it sets includeFwd and includeGen to false, so it emits no method at all. codegen already needed a toolchain recent enough to observe guarded source files; it now also needs one that can parse what it emits. The go.work floor records that, but GOTOOLCHAIN=local ignores a toolchain directive, which is how the oldstable leg reaches go1.26 in the first place. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.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.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist