summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"];
-}