force imported thunks when assigned to a variable

This commit is contained in:
Folkert 2021-12-31 21:44:07 +01:00
parent f767014f30
commit ee9f0b2f04

View file

@ -6307,14 +6307,21 @@ fn handle_variable_aliasing<'a>(
right: Symbol,
mut result: Stmt<'a>,
) -> Stmt<'a> {
if env.is_imported_symbol(right) {
if procs.is_imported_module_thunk(right) {
// if this is an imported symbol, then we must make sure it is
// specialized, and wrap the original in a function pointer.
add_needed_external(procs, env, variable, right);
// then we must construct its closure; since imported symbols have no closure, we use the
// empty struct
let res_layout = layout_cache.from_var(env.arena, variable, env.subs);
let layout = return_on_layout_error!(env, res_layout);
force_thunk(env, right, layout, left, env.arena.alloc(result))
} else if env.is_imported_symbol(right) {
// if this is an imported symbol, then we must make sure it is
// specialized, and wrap the original in a function pointer.
add_needed_external(procs, env, variable, right);
// then we must construct its closure; since imported symbols have no closure, we use the empty struct
let_empty_struct(left, env.arena.alloc(result))
} else {
substitute_in_exprs(env.arena, &mut result, left, right);