aboutsummaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-09 16:03:38 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-03-09 16:03:38 -0500
commitb04a1b30903636bf97a8e04efe88e8a177855bcb (patch)
treed85a765c07c3cc686485d30ef7a4216f4d830cad /types.c
parent42da91936e50ab652d140677689b519fe9deb3fe (diff)
Implement lambdas and closures
Diffstat (limited to 'types.c')
-rw-r--r--types.c21
1 files changed, 2 insertions, 19 deletions
diff --git a/types.c b/types.c
index 0b08cf95..10a5a7a8 100644
--- a/types.c
+++ b/types.c
@@ -28,7 +28,7 @@ CORD type_to_cord(type_t *t) {
return CORD_asprintf("{%r=>%r}", type_to_cord(table->key_type), type_to_cord(table->value_type));
}
case ClosureType: {
- return CORD_all("~", type_to_cord(Match(t, ClosureType)->fn));
+ return type_to_cord(Match(t, ClosureType)->fn);
}
case FunctionType: {
CORD c = "func(";
@@ -261,24 +261,7 @@ bool can_promote(type_t *actual, type_t *needed)
}
if (needed->tag == ClosureType && actual->tag == FunctionType)
- return can_promote(actual, Match(needed, ClosureType)->fn);
-
- // Function promotion:
- if (needed->tag == FunctionType && actual->tag == FunctionType) {
- auto needed_fn = Match(needed, FunctionType);
- auto actual_fn = Match(actual, FunctionType);
- for (arg_t *needed_arg = needed_fn->args, *actual_arg = actual_fn->args;
- needed_arg || actual_arg;
- needed_arg = needed_arg->next, actual_arg = actual_arg->next) {
-
- if (!needed_arg || !actual_arg)
- return false;
-
- if (!type_eq(needed_arg->type, actual_arg->type))
- return false;
- }
- return true;
- }
+ return type_eq(actual, Match(needed, ClosureType)->fn);
return false;
}