Fix up some promotion logic for closures
This commit is contained in:
parent
ff9f4fe6cf
commit
e171d4a98c
@ -47,15 +47,18 @@ static bool promote(env_t *env, CORD *code, type_t *actual, type_t *needed)
|
||||
return promote(env, code, Match(actual, PointerType)->pointed, needed);
|
||||
}
|
||||
|
||||
// Optional promotion:
|
||||
// Optional and stack ref promotion:
|
||||
if (actual->tag == PointerType && needed->tag == PointerType)
|
||||
return true;
|
||||
|
||||
if (needed->tag == ClosureType && actual->tag == FunctionType && type_eq(actual, Match(needed, ClosureType)->fn)) {
|
||||
if (needed->tag == ClosureType && actual->tag == FunctionType) {
|
||||
*code = CORD_all("(closure_t){", *code, ", NULL}");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (needed->tag == ClosureType && actual->tag == ClosureType)
|
||||
return true;
|
||||
|
||||
if (needed->tag == FunctionType && actual->tag == FunctionType) {
|
||||
*code = CORD_all("(", compile_type(env, needed), ")", *code);
|
||||
return true;
|
||||
|
5
types.c
5
types.c
@ -268,7 +268,10 @@ bool can_promote(type_t *actual, type_t *needed)
|
||||
}
|
||||
|
||||
if (needed->tag == ClosureType && actual->tag == FunctionType)
|
||||
return type_eq(actual, Match(needed, ClosureType)->fn);
|
||||
return can_promote(actual, Match(needed, ClosureType)->fn);
|
||||
|
||||
if (needed->tag == ClosureType && actual->tag == ClosureType)
|
||||
return can_promote(Match(actual, ClosureType)->fn, 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;
|
||||
|
Loading…
Reference in New Issue
Block a user