Improve #optional_ok logic for procedures; Add #optional_second for package runtime usage

This commit is contained in:
gingerBill
2021-04-19 22:31:14 +01:00
parent 0eb75886d1
commit f1bdd2e60f
4 changed files with 131 additions and 99 deletions
+18
View File
@@ -2450,6 +2450,24 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
}
}
}
if (pt->tags & ProcTag_optional_second) {
if (optional_ok) {
error(proc_type_node, "A procedure type cannot have both an #optional_ok tag and #optional_second");
}
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);
} else {
bool ok = false;
if (proc_type_node->file && proc_type_node->file->pkg) {
ok = proc_type_node->file->pkg->scope == ctx->info->runtime_package->scope;
}
if (!ok) {
error(proc_type_node, "A procedure type with the #optional_second may only be allowed within 'package runtime'");
}
}
}
type->Proc.node = proc_type_node;
type->Proc.scope = c->scope;