From 80505a7eb147422226d1b86da17f516982d0f4c8 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 23 Nov 2025 13:52:15 -0500 Subject: Better error messages and bugfix for compile_to_type logic --- src/types.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/types.c') diff --git a/src/types.c b/src/types.c index 51555560..edfee27d 100644 --- a/src/types.c +++ b/src/types.c @@ -12,6 +12,15 @@ #include "stdlib/util.h" #include "types.h" +Text_t arg_types_to_text(arg_t *args, const char *separator) { + Text_t text = EMPTY_TEXT; + for (arg_t *arg = args; arg; arg = arg->next) { + text = Texts(text, type_to_text(arg->type)); + if (arg->next) text = Texts(text, separator); + } + return text; +} + Text_t type_to_text(type_t *t) { if (!t) return Text("(Unknown type)"); @@ -45,15 +54,11 @@ Text_t type_to_text(type_t *t) { return type_to_text(Match(t, ClosureType)->fn); } case FunctionType: { - Text_t c = Text("func("); DeclareMatch(fn, t, FunctionType); - for (arg_t *arg = fn->args; arg; arg = arg->next) { - c = Texts(c, type_to_text(arg->type)); - if (arg->next) c = Texts(c, ","); - } - if (fn->ret && fn->ret->tag != VoidType) c = Texts(c, fn->args ? " -> " : "-> ", type_to_text(fn->ret)); - c = Texts(c, ")"); - return c; + Text_t text = Texts("func(", arg_types_to_text(fn->args, ",")); + if (fn->ret && fn->ret->tag != VoidType) text = Texts(text, fn->args ? " -> " : "-> ", type_to_text(fn->ret)); + text = Texts(text, ")"); + return text; } case StructType: { DeclareMatch(struct_, t, StructType); -- cgit v1.2.3