From 82cac572ca52c4687e8adeaafa87de5cd2c44970 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 21 Aug 2024 19:00:25 -0400 Subject: [PATCH] lang: core: fmt: Allow type unification variables for format This allows some simple cases. --- lang/core/fmt/printf_func.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/core/fmt/printf_func.go b/lang/core/fmt/printf_func.go index 50bbf158..d465cc5d 100644 --- a/lang/core/fmt/printf_func.go +++ b/lang/core/fmt/printf_func.go @@ -124,7 +124,7 @@ func (obj *PrintfFunc) FuncInfer(partialType *types.Type, partialValues []types. // programming error? return nil, nil, fmt.Errorf("must have at least one arg") } - if typ := partialType.Map[partialType.Ord[0]]; typ != nil && typ.Cmp(types.TypeStr) != nil { + if typ := partialType.Map[partialType.Ord[0]]; typ != nil && typ.Cmp(types.TypeStr) != nil && !typ.HasUni() { return nil, nil, fmt.Errorf("format string was a %s", typ) } @@ -193,7 +193,7 @@ func (obj *PrintfFunc) FuncInfer(partialType *types.Type, partialValues []types. } // Check the format string is consistent with what we've found earlier! - if i := 0; typList[i] != nil && typList[i].Cmp(types.TypeStr) != nil { + if i := 0; typList[i] != nil && typList[i].Cmp(types.TypeStr) != nil && !typList[i].HasUni() { return nil, nil, fmt.Errorf("inconsistent type at arg index %d (format string)", i) } typList[0] = types.TypeStr // format string (zeroth arg)