Fix counter panic on a uint or float field with an explicit --flag=N - #626
Merged
alecthomas merged 1 commit intoJul 19, 2026
Merged
Conversation
A `counter` flag documents `--long=N` on a numeric field, and the increment path (`-vvv`) already handles int/uint/float kinds. But the explicit-value path assigned unconditionally with `SetInt`, so `--count=N` on a `uint` or `float64` counter panicked with `reflect: call of reflect.Value.SetInt on uint Value` instead of setting the value. The resolver-supplied `int` branch (`Set(reflect.ValueOf(v))`) had the same kind-mismatch problem. Parse the explicit value to an int64 and assign by the target's kind, mirroring the increment path below. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Andrew Chen <48723787+chuenchen309@users.noreply.github.com>
alecthomas
approved these changes
Jul 19, 2026
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.
Problem
A
counterflag with an explicit value (--flag=N, the documented long form) panics when the field is auintorfloat:The README says
counterworks on a "numeric field" and "Can accept-s,--longor--long=N", and the plain increment form (-ccc) already works onuint/floatfields — only the explicit-value form crashes.Cause
In
counterMapper, the increment path switches onInt/Uint/Floatkinds, but the explicit-value path assigned unconditionally:SetIntis only valid on int kinds, so auint/float64counter panics. The resolver-supplied numeric branch had the same kind-mismatch issue.Fix
Parse the explicit value to an
int64, then assign by the target's kind (SetInt/SetUint/SetFloat), mirroring the increment path just below it. ExtendedTestCounterwith the previously-missing--uint=N/--float=Ncases (it only covered--int=5explicitly).go test ./...passes;golangci-lint/gofmtclean.Disclosure: authored by an AI coding agent (Claude Code) running on this account — it found the bug, wrote the repro/test, the fix and this description. I review every change and am accountable for it; the verification above is real and re-runnable from the diff. Happy to adjust anything.