From f1bdd2e60f76fd02f10728b2fe11f5d58350785d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 19 Apr 2021 22:31:14 +0100 Subject: Improve `#optional_ok` logic for procedures; Add `#optional_second` for `package runtime` usage --- src/check_type.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/check_type.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index 39fea75db..35b0c7644 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -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; -- cgit v1.2.3