aboutsummaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-05-12 16:09:24 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-05-12 16:09:24 -0400
commit3c50c182a88609d4a8bbb16255ba56d414440f63 (patch)
tree36ba2b4f0675decf0a82419f91224364093dd7b9 /types.c
parent3481042259c1db4d9fb4e50d5e91e8c58e8cdac5 (diff)
Typecheck method promotion for interfaces
Diffstat (limited to 'types.c')
-rw-r--r--types.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/types.c b/types.c
index 85060b4c..ca0f77f3 100644
--- a/types.c
+++ b/types.c
@@ -270,6 +270,19 @@ bool can_promote(type_t *actual, type_t *needed)
if (needed->tag == ClosureType && actual->tag == FunctionType)
return type_eq(actual, Match(needed, ClosureType)->fn);
+ if (actual->tag == FunctionType && needed->tag == FunctionType) {
+ for (arg_t *actual_arg = Match(actual, FunctionType)->args, *needed_arg = Match(needed, FunctionType)->args;
+ actual_arg || needed_arg; actual_arg = actual_arg->next, needed_arg = needed_arg->next) {
+ if (!actual_arg || !needed_arg) return false;
+ if (type_eq(actual_arg->type, needed_arg->type)) continue;
+ if (actual_arg->type->tag == PointerType && needed_arg->type->tag == PointerType
+ && can_promote(actual_arg->type, needed_arg->type))
+ continue;
+ return false;
+ }
+ return true;
+ }
+
return false;
}