Report a prep-time arg that its check should have caught

calcPrep discarded parseCalc's error, so a divergence from checkCalc would
have produced a nil AST and then a nil dereference per render, with no
message. atoi did the same quietly, returning zero for a length, range or
decimal count. Both now panic naming the argument, so the invariant they rest
on fails where it breaks.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
M
2026-08-31 14:02:35 +02:00
committed by lilleman-tw
parent 2e187117f8
commit 0cee8b2183
2 changed files with 14 additions and 3 deletions
+4 -1
View File
@@ -96,7 +96,10 @@ func checkCalc(fields map[string]node, args []string) error {
// operand name at the position expand will read it into. checkCalc proved both args
// valid, so no step here can fail; dp -1 prints the minimal form.
func calcPrep(args []string) callFn {
expr, _ := parseCalc(args[0])
expr, err := parseCalc(args[0])
if err != nil { // a nil AST would be a nil dereference per render, with no message
panic(fmt.Sprintf("fakes: calc(%q) reached prep unparsed: %v", args[0], err))
}
at := make(map[string]int)
for i, name := range calcVars(expr) {
at[name] = i