aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-09-12 13:08:32 +0100
committergingerBill <bill@gingerbill.org>2022-09-12 13:08:32 +0100
commitef372bd86194a01f6386fd1eae71e7362e28cf89 (patch)
treef418c4493ab2d0d23c12f05c47bf5e53ce7d7126 /src/check_type.cpp
parentfbbfe438dc8d841bdba6585c7b80336b569a01f0 (diff)
Replace `#optional_second` with `#optional_allocator_error`
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index 66417f97e..c024e0842 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -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);
}
}
}