diff options
| author | gingerBill <bill@gingerbill.org> | 2021-04-19 22:31:14 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-04-19 22:31:14 +0100 |
| commit | f1bdd2e60f76fd02f10728b2fe11f5d58350785d (patch) | |
| tree | 170952c8524daab434fe67e04fbbdd81f0f8bb02 /src/check_type.cpp | |
| parent | 0eb75886d16307091d5379d53fac9a3cca8d5a7d (diff) | |
Improve `#optional_ok` logic for procedures; Add `#optional_second` for `package runtime` usage
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
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; |