From 876834ff291cc03f639e35b2a0412e79a72ae47c Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sat, 24 May 2025 21:03:19 -0400 Subject: [PATCH] lang: core: fmt: Catch printf edge case --- lang/core/fmt/printf.go | 3 +++ lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lang/core/fmt/printf.go b/lang/core/fmt/printf.go index 9bb6ad3f..11fe7261 100644 --- a/lang/core/fmt/printf.go +++ b/lang/core/fmt/printf.go @@ -169,6 +169,9 @@ func (obj *PrintfFunc) FuncInfer(partialType *types.Type, partialValues []types. if err != nil { return nil, nil, errwrap.Wrapf(err, "could not parse format string") } + if a, l := len(typList)-1, len(formatList); a != l { + return nil, nil, fmt.Errorf("number of args (%d) doesn't match format string verb count (%d)", a, l) + } for i, x := range typList { if i == 0 { // format string continue diff --git a/lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar b/lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar index 61f4bd55..ff0f5b94 100644 --- a/lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar +++ b/lang/interpret_test/TestAstFunc2/printfunificationerr0.txtar @@ -2,4 +2,4 @@ import "fmt" test fmt.printf("%d%d", 42) {} # should not pass, missing second int -- OUTPUT -- -# err: errUnify: type error: str != list: /main.mcl @ 2:1-2:30 +# err: errUnify: func `printf` infer error: number of args (1) doesn't match format string verb count (2)