Repository navigation
checker, transform: fix generic regressions exposed by the strconv Numeric constraint - #29444
Merged
medvednikov merged 2 commits intoOct 4, 2026
Merged
Conversation
…int walk Since strconv declares `Numeric` (vlang#29396), every program declares a constraint, so the constraint walk runs over the body of every generic function. Resolving a chained call there, `sb.str().trim_space()`, checks the receiver call `sb.str()`, where the walk binds `sb` without its `mut`, and that check reported `sb` as immutable. The walk now drops what resolving a call reports: it reports what the constraints forbid, and the body is checked where it is instantiated. This covers every way a body binds a local (declarations, multi-returns, `if mut x :=` guards, `for mut x in`, or-blocks), and `shared` locals in `lock` blocks, which the walk does not track either.
… type `m is T` on a `Maybe[&int]` did not find the `&int` variant from the trimmed pattern `int`, and fell back to the first module sum type with an `int` variant, `strconv.Numeric` since vlang#29396, which generated `m.strconv__andint` for the smartcast. When the subject is a sum type, the pattern is a variant of that sum type: fall back to it rather than to any other sum type.
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.
Since #29396 (
strconv: use generic constraints for format_thousands),strconvdeclares theNumericconstraint, and every program importsstrconvthroughbuiltin. That exposed two existing compiler bugs in every program:x is immutablein generic functions.program_declares_constraints()is now always true, so the generic constraint walk runs over every generic body. The walk binds locals without theirmut, so resolving a chained call such assb.str().trim_space()on amut sbreportedsbas immutable. This broke 19 test files invlib/encoding/cbor,vlib/encoding/coseandvlib/encoding/cwt(generic.v:122:21: error: ksub is immutable), and any user generic function with the same pattern.Fix: the walk now drops what resolving a call reports. It only reports what the constraints forbid; the body is still fully checked where it is instantiated.
C error for smartcasts on a generic sum type over a pointer (
vlib/v/tests/generics/generic_sumtype_str_test.v:no member named 'strconv__andint' in 'struct Maybe_ptrint').m is Ton aMaybe[&int]did not find the&intvariant from the trimmedint, and fell back to the first module sum type with anintvariant, which is nowstrconv.Numeric.Fix: when the subject is a sum type, never take another sum type's variant.
Both regression tests declare their own constraint and sum type, so they keep guarding these bugs whatever
strconvdeclares.