From da4f69cd8756485bd3645896fa9d22bbfb39e552 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 21 Aug 2024 18:52:24 -0400 Subject: [PATCH] lang: ast, core: fmt: Allow unification variables for fmt This lets us pass through unification variables into the fmt function. I hope this doesn't break anything, but it's worth trying for now. --- lang/ast/structs.go | 1 + lang/core/fmt/printf_func.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lang/ast/structs.go b/lang/ast/structs.go index 72969ec0..32d8b3ac 100644 --- a/lang/ast/structs.go +++ b/lang/ast/structs.go @@ -8307,6 +8307,7 @@ func (obj *ExprCall) getPartials(fn *ExprFunc) (*types.Type, []types.Value, erro // optimization: if type/value is already known, specify it now! var err1, err2 error + // NOTE: This _can_ return unification variables now. Is it ok? mapped[name], err1 = arg.Type() // nil type on error partialValues[i], err2 = arg.Value() // nil value on error if err1 == nil && err2 == nil && mapped[name].Cmp(partialValues[i].Type()) != nil { diff --git a/lang/core/fmt/printf_func.go b/lang/core/fmt/printf_func.go index c1842c02..50bbf158 100644 --- a/lang/core/fmt/printf_func.go +++ b/lang/core/fmt/printf_func.go @@ -175,11 +175,11 @@ func (obj *PrintfFunc) FuncInfer(partialType *types.Type, partialValues []types. continue } - // Assume x does not contain unification variables! - if x.HasUni() { - // programming error (did the compiler change?) - return nil, nil, fmt.Errorf("programming error at arg index %d", i) - } + // NOTE: Is it okay to allow unification variables here? + //if x.HasUni() { + // // programming error (did the compiler change?) + // return nil, nil, fmt.Errorf("programming error at arg index %d", i) + //} if err := unificationUtil.UnifyCmp(x, formatList[i-1]); err != nil { return nil, nil, errwrap.Wrapf(err, "inconsistent type at arg index %d", i) }