Replace #optional_second with #optional_allocator_error

This commit is contained in:
gingerBill
2022-09-12 13:08:32 +01:00
parent fbbfe438dc
commit ef372bd861
9 changed files with 26 additions and 35 deletions
+9 -10
View File
@@ -2006,22 +2006,21 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
}
}
}
if (pt->tags & ProcTag_optional_second) {
if (pt->tags & ProcTag_optional_allocator_error) {
if (optional_ok) {
error(proc_type_node, "A procedure type cannot have both an #optional_ok tag and #optional_second");
error(proc_type_node, "A procedure type cannot have both an #optional_ok tag and #optional_allocator_error");
}
optional_ok = true;
if (result_count != 2) {
error(proc_type_node, "A procedure type with the #optional_second tag requires 2 return values, got %td", result_count);
error(proc_type_node, "A procedure type with the #optional_allocator_error tag requires 2 return values, got %td", result_count);
} else {
bool ok = false;
AstFile *file = proc_type_node->file();
if (file && file->pkg) {
ok = file->pkg->scope == ctx->info->runtime_package->scope;
}
init_mem_allocator(c->checker);
if (!ok) {
error(proc_type_node, "A procedure type with the #optional_second may only be allowed within 'package runtime'");
Type *type = results->Tuple.variables[1]->type;
if (!are_types_identical(type, t_allocator_error)) {
gbString t = type_to_string(type);
error(proc_type_node, "A procedure type with the #optional_allocator_error expects a `runtime.Allocator_Error`, got '%s'", t);
gb_string_free(t);
}
}
}