lang: core: fmt: Catch printf edge case
This commit is contained in:
@@ -169,6 +169,9 @@ func (obj *PrintfFunc) FuncInfer(partialType *types.Type, partialValues []types.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errwrap.Wrapf(err, "could not parse format string")
|
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 {
|
for i, x := range typList {
|
||||||
if i == 0 { // format string
|
if i == 0 { // format string
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
test fmt.printf("%d%d", 42) {} # should not pass, missing second int
|
test fmt.printf("%d%d", 42) {} # should not pass, missing second int
|
||||||
-- OUTPUT --
|
-- 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user