summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-04-01 17:44:43 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-04-01 17:44:43 -0400
commita251f565b97987dbd505f7f063d9a8e041036b3c (patch)
tree655cf44d9e7ba25c23d5959878195637bab13127
parent157ffb0e7c17c61d05462e5ffdce19620485b0b1 (diff)
fixed the fact that sometimes you didnt get redeclaration errors
-rw-r--r--err.c13
-rw-r--r--parse.c4
-rw-r--r--test.toc15
3 files changed, 7 insertions, 25 deletions
diff --git a/err.c b/err.c
index 6c3acb9..48fefca 100644
--- a/err.c
+++ b/err.c
@@ -70,14 +70,11 @@ static void print_pos_highlight(FILE *out, ErrCtx *ctx, File *file, U32 start_po
}
static void print_location_highlight(FILE *out, Location where) {
- if (where.start) {
- File *f = where.file;
- ErrCtx *ctx = f->ctx;
- Token *first = &f->tokens[where.start];
- Token *last = &f->tokens[where.end-1];
- print_pos_highlight(out, ctx, f, first->pos.start, last->pos.end);
- }
-
+ File *f = where.file;
+ ErrCtx *ctx = f->ctx;
+ Token *first = &f->tokens[where.start];
+ Token *last = &f->tokens[where.end-1];
+ print_pos_highlight(out, ctx, f, first->pos.start, last->pos.end);
}
/* for debugging */
diff --git a/parse.c b/parse.c
index f269ea9..1cf18bf 100644
--- a/parse.c
+++ b/parse.c
@@ -1002,8 +1002,8 @@ static Identifier parser_ident_insert(Parser *p, char *str) {
static Status check_ident_redecl(Parser *p, Identifier i) {
Tokenizer *t = p->tokr;
- if (i->idents == &p->block->idents) {
- if (i->decl_kind != IDECL_NONE) {
+ if (i->idents == (p->block ? &p->block->idents : p->globals)) { /* in the same scope */
+ if (i->decl_kind != IDECL_NONE) { /* declared */
char *s = ident_to_str(i);
tokr_err(t, "Redeclaration of identifier %s.", s);
info_print(ident_decl_location(p->file, i), "Previous declaration was here.");
diff --git a/test.toc b/test.toc
index fc21dc4..f0004fa 100644
--- a/test.toc
+++ b/test.toc
@@ -1,19 +1,4 @@
#include "std/io.toc";
-
-s ::= fn(t:: Type) Type {
- struct {
- c :: t = 7 as t;
- m: t;
- }
-}
-puti ::= fn() {
-}
-
puti ::= fn() {
}
-main ::= fn() {
- o: s(int);
- x := o["m"];
- y ::= o["c"];
-}