aboutsummaryrefslogtreecommitdiff
path: root/src/checker/stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <ginger.bill.22@gmail.com>2016-08-23 00:03:53 +0100
committergingerBill <ginger.bill.22@gmail.com>2016-08-23 00:03:53 +0100
commitaaecb18c8f37a7f7feb3400178633819859b642f (patch)
tree57667583efc5199150bd1b4d7fcbc93b97a1575d /src/checker/stmt.cpp
parent81c592b5e92411e4b64744a152bd445bb6154433 (diff)
Fix procedure's scope
Diffstat (limited to 'src/checker/stmt.cpp')
-rw-r--r--src/checker/stmt.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/checker/stmt.cpp b/src/checker/stmt.cpp
index 197ab1bb0..a78db4623 100644
--- a/src/checker/stmt.cpp
+++ b/src/checker/stmt.cpp
@@ -190,7 +190,7 @@ Type *check_assignment_variable(Checker *c, Operand *op_a, AstNode *lhs) {
b32 used = false;
if (node->kind == AstNode_Ident) {
ast_node(i, Ident, node);
- e = scope_lookup_entity(c->context.scope, i->token.string);
+ e = scope_lookup_entity(c, c->context.scope, i->token.string);
if (e != NULL && e->kind == Entity_Variable) {
used = e->Variable.used; // TODO(bill): Make backup just in case
}
@@ -398,20 +398,34 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d, b32 check_body_later) {
e->type = proc_type;
ast_node(pd, ProcDecl, d->proc_decl);
- Scope *original_curr_scope = c->context.scope;
- c->context.scope = c->global_scope;
check_open_scope(c, pd->type);
defer ({
check_close_scope(c);
- c->context.scope = original_curr_scope;
});
check_procedure_type(c, proc_type, pd->type);
- b32 is_foreign = (pd->tags & ProcTag_foreign) != 0;
- b32 is_inline = (pd->tags & ProcTag_inline) != 0;
+ b32 is_foreign = (pd->tags & ProcTag_foreign) != 0;
+ b32 is_inline = (pd->tags & ProcTag_inline) != 0;
b32 is_no_inline = (pd->tags & ProcTag_no_inline) != 0;
+
+
+ if (d->scope == c->global_scope &&
+ are_strings_equal(e->token.string, make_string("main"))) {
+ if (proc_type != NULL) {
+ auto *pt = &proc_type->proc;
+ if (pt->param_count != 0 ||
+ pt->result_count) {
+ gbString str = type_to_string(proc_type);
+ defer (gb_string_free(str));
+
+ error(&c->error_collector, e->token,
+ "Procedure type of `main` was expected to be `proc()`, got %s", str);
+ }
+ }
+ }
+
if (is_inline && is_no_inline) {
error(&c->error_collector, ast_node_token(pd->type),
"You cannot apply both `inline` and `no_inline` to a procedure");