Speculative fix for some incref issues
This commit is contained in:
parent
89a1f8a401
commit
dc7ee868a6
21
compile.c
21
compile.c
@ -91,7 +91,10 @@ static bool promote(env_t *env, CORD *code, type_t *actual, type_t *needed)
|
||||
CORD compile_maybe_incref(env_t *env, ast_t *ast)
|
||||
{
|
||||
type_t *t = get_type(env, ast);
|
||||
if (is_idempotent(ast) && can_be_mutated(env, ast)) {
|
||||
// TODO: not sure if this is underkill or not, but a
|
||||
// bug was happening with `"":join(table.keys)`
|
||||
// if (is_idempotent(ast) && can_be_mutated(env, ast)) {
|
||||
if (ast->tag == Var && can_be_mutated(env, ast)) {
|
||||
if (t->tag == ArrayType)
|
||||
return CORD_all("ARRAY_COPY(", compile(env, ast), ")");
|
||||
else if (t->tag == TableType || t->tag == SetType)
|
||||
@ -1006,7 +1009,7 @@ CORD compile_statement(env_t *env, ast_t *ast)
|
||||
loop = CORD_all(loop, "{\n", naked_body, "\n}");
|
||||
}
|
||||
|
||||
if (can_be_mutated(env, array) && is_idempotent(array)) {
|
||||
if (can_be_mutated(env, array) && is_idempotent(array) && array->tag == Var) {
|
||||
CORD array_code = compile(env, array);
|
||||
loop = CORD_all("{\n"
|
||||
"Array_t iterating = ARRAY_COPY(", array_code, ");\n",
|
||||
@ -1410,12 +1413,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t
|
||||
} else {
|
||||
env_t *arg_env = with_enum_scope(env, spec_arg->type);
|
||||
type_t *actual_t = get_type(arg_env, call_arg->value);
|
||||
// TODO: not sure if this should always be incref'd or not,
|
||||
// bug was happening with `"":join(table.keys)`
|
||||
if (call_arg->value->tag == Var)
|
||||
value = compile_maybe_incref(arg_env, call_arg->value);
|
||||
else
|
||||
value = compile(arg_env, call_arg->value);
|
||||
value = compile_maybe_incref(arg_env, call_arg->value);
|
||||
if (!promote(arg_env, &value, actual_t, spec_arg->type))
|
||||
code_err(call_arg->value, "This argument is supposed to be a %T, but this value is a %T", spec_arg->type, actual_t);
|
||||
}
|
||||
@ -1443,12 +1441,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t
|
||||
} else {
|
||||
env_t *arg_env = with_enum_scope(env, spec_arg->type);
|
||||
type_t *actual_t = get_type(arg_env, call_arg->value);
|
||||
// TODO: not sure if this should always be incref'd or not,
|
||||
// bug was happening with `"":join(table.keys)`
|
||||
if (call_arg->value->tag == Var)
|
||||
value = compile_maybe_incref(arg_env, call_arg->value);
|
||||
else
|
||||
value = compile(arg_env, call_arg->value);
|
||||
value = compile_maybe_incref(arg_env, call_arg->value);
|
||||
if (!promote(arg_env, &value, actual_t, spec_arg->type))
|
||||
code_err(call_arg->value, "This argument is supposed to be a %T, but this value is a %T", spec_arg->type, actual_t);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user