Repository navigation
strconv: use generic constraints for format_thousands - #29396
Merged
medvednikov merged 2 commits intoOct 4, 2026
Merged
Conversation
…2 vlib Make `strconv.Numeric` public, so generic code that forwards a `T` to `format_thousands` can constrain it with `[T strconv.Numeric]`, and list the exact accepted types in its documentation. Cover every integer type and a constrained generic wrapper in the tests. `[T Numeric]` is the first constraint in a module that every program imports (through `builtin`), and the V 0.5.2 compatibility compiler cannot parse it. 9d7a2a7 ran the `-check` fixtures in vlib/v/checker/tests/with_check_option/ with that compiler against the current vlib, so all 4 of them (and compiler_errors_test.v) failed. Run them against the compatibility compiler's own vlib instead, like the other fixtures routed to it. Only the JSON cgen fixtures still get the current vlib; none exist since the cJSON `json` module was removed. Checked that nothing else needs V 0.5.2 to parse the current vlib: - all 4 with_check_option fixtures match their .out byte for byte, and the 3 legacy compiler module fixtures still match theirs; - make/`v self` bootstrap from vc/v.c, which is generated from master and already parses constraints: a v1 built from the current vc snapshot with -DCUSTOM_DEFINE_v1_fallback compiles cmd/v with this vlib; vc generation and `v up` use the current compiler; - `-old-compiler`, the automatic V1 retry, `-vls-mode` and `build-module` already use the fallback's own vroot (or map module paths into it), and work with this change; - CI only greps for unexpected V1 fallbacks; it never runs the compatibility compiler on this repository's vlib.
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.
Replace the manual
$if T !in [...] { $compile_error(...) }check informat_thousands with the native generic constraint syntax added
recently:
format_thousands[T Numeric]. The compiler now enforcesthe same restriction at both the call site and inside the body,
instead of a hand-written comptime check that has to be kept in
sync by hand.
Also:
Numeric, which had no doc commenttypes by hand (now just refers to
Numeric)add_thousands_sep/format_thousandsdoc examples to usethe ```v fenced block vlib's doc tooling expects, so
v doc -check-examplesactually compiles and checks them insteadof silently skipping them
Note: This uses the new generic type parameter constraint syntax (
[T Numeric]) added in #29254. Building this branch requires avtoolchain built from a commit at or after that merge — an older localvbinary will either reject[T Numeric]outright or (on pre-#29254 parsers) silently drop the constraint, soformat_thousandswould compile without the intended type-safety guarantee. If CI or a reviewer sees unexpected generics errors here, check that the toolchain includes #29254 first.