aboutsummaryrefslogtreecommitdiff
path: root/src/types.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-11-23 13:52:15 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-11-23 13:52:15 -0500
commit80505a7eb147422226d1b86da17f516982d0f4c8 (patch)
tree9265fd867d115711192705e6688a29df573fd057 /src/types.c
parent0fa9a52090eb5d9ce88220c0134a8d2af6eb8d94 (diff)
Better error messages and bugfix for compile_to_type logic
Diffstat (limited to 'src/types.c')
-rw-r--r--src/types.c21
1 files changed, 13 insertions, 8 deletions
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);