codegen w/ go version guards - ErrorAsType (go1.26)#132
Merged
Conversation
Add the infrastructure for assertions guarded by a //go:build go1.N constraint, so the library can offer functionality that requires a newer Go toolchain while still building on oldstable (currently go1.25). No guarded assertion exists yet; this is the prerequisite mechanism. Codegen: - scanner: detect each function's source-file //go:build constraint (via go/build/constraint) and record it on model.Function.GoBuild. - model: GoBuildTag, Functions.BuildVariants, AssertionPackage.BuildConstraint. - generator: partition functions by constraint and render a parallel set of files suffixed _go<N> carrying the //go:build line; render() skips/removes files with no declarations; a shared header.gotmpl emits the guard; file-level boilerplate (Assertions/New, forwardArgs, mock types, shared test fixtures) is gated to the default partition so guarded files reference it instead of redeclaring it. - orphan cleanup: sweepOrphanVariants removes generated *_go<N>* files whose variant no longer exists, but only marker-bearing, non-hand-authored files, logging every removal. - safety rail: go.work carries a toolchain floor (go1.26.0) so codegen, run in workspace mode, always observes guarded files; TestToolchainFloorCoversGuards asserts the highest guard does not exceed the floor. The floor is dev-only and not published, so consumers on older toolchains are unaffected. Doc site (Hugo): - new goversion shortcode renders an explicit "minimum Go version" pill (styled in custom-header.html); domain pages and the quick index gain the conditional plumbing (Document.HasGoGuards, QuickIndexEntry.GoBuild) to show it. Because no assertion is guarded yet, regenerated output is byte-identical to the current generated packages and docs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Add ErrorAsType and its opposite NotErrorAsType, guarded behind //go:build go1.26 in internal/assertions/error_go126.go and built on go1.26 errors.AsType[E]. These are the first assertions to use the codegen go-version guard mechanism. Design (keeping the assertion conventions intact): - Assertions return bool, not the upstream errors.AsType (E, bool) shape. The matched error is delivered through a typed target *E (the type-safe counterpart of ErrorAs's untyped any target). - target is nilable: pass &got to capture the matched error (E inferred), or nil to only check, supplying E explicitly e.g. ErrorAsType[*json.SyntaxError](t, err, nil). - Because E is inferable from target *E, these are ordinary inferable generics: no GenericSuffix special-case and no codegen changes; the //go:build go1.26 guard flows through the generator and into the doc site (error domain gains the go1.26 badge) automatically. The nil (check-only) branch, which the example-driven generated tests cannot exercise, is covered by a hand-written guarded test (error_go126_test.go). Refers to stretchr#1860 (adapted: typed *E target with bool return). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
- CHANGES.md: document ErrorAsType / NotErrorAsType in the Error domain (go1.26 generics, adapted from upstream stretchr#1860 with a typed *E target and bool return). - TRACKING.md: move stretchr#1860 from "Monitoring" to "Implemented"; add it to the highlight list and the appendix table; bump summary stats (implemented 27->28, monitoring 2->1). - ROADMAP.md: mark v2.6 (June 2026) done and drop the "tentative" tag; add a Q3 2026 section with a tentative v2.7 (Sep 2026) for generic forward methods (go1.27+); refresh the processed-items stat line to match TRACKING. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #132 +/- ##
==========================================
- Coverage 91.70% 91.62% -0.08%
==========================================
Files 97 103 +6
Lines 12651 12834 +183
==========================================
+ Hits 11601 11759 +158
- Misses 827 840 +13
- Partials 223 235 +12 ☔ View full report in Codecov by Harness. |
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