aboutsummaryrefslogtreecommitdiff
path: root/src/check_decl.cpp
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-07-17 15:08:36 +0100
committerGinger Bill <bill@gingerbill.org>2017-07-17 15:08:36 +0100
commit9a8759efefa24f5ae1e6d91b67dca72357a99ff9 (patch)
treef0c5087618010a4fa4d85cbe019426f9c18a7ede /src/check_decl.cpp
parent054948e701c1340e72ac236d58da15ca9e6d617c (diff)
Polymorphic type specialization for procedures
Diffstat (limited to 'src/check_decl.cpp')
-rw-r--r--src/check_decl.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 7c33cf9e5..38923e494 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -60,7 +60,9 @@ Type *check_init_variable(Checker *c, Entity *e, Operand *operand, String contex
t = default_type(t);
}
if (is_type_polymorphic(t)) {
- error(e->token, "Invalid use of a polymorphic type in %.*s", LIT(context_name));
+ gbString str = type_to_string(t);
+ defer (gb_string_free(str));
+ error(e->token, "Invalid use of a polymorphic type `%s` in %.*s", str, LIT(context_name));
e->type = t_invalid;
return nullptr;
}
@@ -400,17 +402,16 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
check_open_scope(c, pl->type);
defer (check_close_scope(c));
- #if 0
- if (e->token.string == "sort") {
- gb_printf_err("%.*s\n", LIT(e->token.string));
- }
- #endif
+
+
auto prev_context = c->context;
c->context.allow_polymorphic_types = true;
check_procedure_type(c, proc_type, pl->type);
c->context = prev_context;
+ TypeProc *pt = &proc_type->Proc;
+
bool is_foreign = (pl->tags & ProcTag_foreign) != 0;
bool is_link_name = (pl->tags & ProcTag_link_name) != 0;
bool is_export = (pl->tags & ProcTag_export) != 0;
@@ -419,7 +420,6 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
bool is_require_results = (pl->tags & ProcTag_require_results) != 0;
- TypeProc *pt = &proc_type->Proc;
if (d->scope->is_file && e->token.string == "main") {
if (pt->param_count != 0 ||
@@ -559,7 +559,9 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
e->type = check_type(c, type_expr);
}
if (e->type != nullptr && is_type_polymorphic(base_type(e->type))) {
- error(e->token, "Invalid use of a polymorphic type in %.*s", LIT(context_name));
+ gbString str = type_to_string(e->type);
+ defer (gb_string_free(str));
+ error(e->token, "Invalid use of a polymorphic type `%s` in %.*s", str, LIT(context_name));
e->type = t_invalid;
}