diff options
| author | Tetralux <tetralux@teknik.io> | 2020-04-22 06:12:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-22 06:12:41 +0100 |
| commit | e7e936f4804d7e5ba5f5cb77818240216a80648b (patch) | |
| tree | 2ad8f308089222f37d32e0e6a3475a2a6d4c1710 /src/check_type.cpp | |
| parent | 3afa2736b7c8826527cb71ec3ca220750e0d2a9e (diff) | |
| parent | 026bb8ed6f6e626c69ccfe32de5b2323d86b4620 (diff) | |
Merge branch 'master' into fix-sync-badopt
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 6df824ec1..73f732b45 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2530,6 +2530,22 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, } GB_ASSERT(cc > 0); + bool optional_ok = (pt->tags & ProcTag_optional_ok) != 0; + if (optional_ok) { + if (result_count != 2) { + error(proc_type_node, "A procedure type with the #optional_ok tag requires 2 return values, got %td", result_count); + } else { + Entity *second = results->Tuple.variables[1]; + if (is_type_polymorphic(second->type)) { + // ignore + } else if (is_type_boolean(second->type)) { + // GOOD + } else { + error(second->token, "Second return value of an #optional_ok procedure must be a boolean, got %s", type_to_string(second->type)); + } + } + } + type->Proc.node = proc_type_node; type->Proc.scope = c->scope; type->Proc.params = params; @@ -2542,6 +2558,7 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, type->Proc.is_polymorphic = pt->generic; type->Proc.specialization_count = specialization_count; type->Proc.diverging = pt->diverging; + type->Proc.optional_ok = optional_ok; type->Proc.tags = pt->tags; if (param_count > 0) { |