aboutsummaryrefslogtreecommitdiff
path: root/src/checker.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-07-27 00:45:36 +0100
committergingerBill <bill@gingerbill.org>2019-07-27 00:45:36 +0100
commit40f0e74b8c93f753479c6d0ed52d0b1a812f6acd (patch)
tree45306bd04c15ec17394c71396fe1a08f324bf12d /src/checker.cpp
parentd26033eb23c74ae4fc83dc6aaf2f2ec6571f2661 (diff)
Change scoping rules to allow for shadowing of procedure parameters but not named return values
Diffstat (limited to 'src/checker.cpp')
-rw-r--r--src/checker.cpp45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index 9abd8c499..f68e2ab15 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -400,6 +400,15 @@ Entity *scope_insert_with_name(Scope *s, String name, Entity *entity) {
if (found) {
return *found;
}
+ if (s->parent != nullptr && (s->parent->flags & ScopeFlag_Proc) != 0) {
+ Entity **found = map_get(&s->parent->elements, key);
+ if (found) {
+ if ((*found)->flags & EntityFlag_Result) {
+ return *found;
+ }
+ }
+ }
+
map_set(&s->elements, key, entity);
if (entity->scope == nullptr) {
entity->scope = s;
@@ -1044,21 +1053,37 @@ bool redeclaration_error(String name, Entity *prev, Entity *found) {
// NOTE(bill): Error should have been handled already
return false;
}
- error(prev->token,
- "Redeclaration of '%.*s' in this scope through 'using'\n"
- "\tat %.*s(%td:%td)",
- LIT(name),
- LIT(up->token.pos.file), up->token.pos.line, up->token.pos.column);
+ if (found->flags & EntityFlag_Result) {
+ error(prev->token,
+ "Direct shadowing of the named return value '%.*s' in this scope through 'using'\n"
+ "\tat %.*s(%td:%td)",
+ LIT(name),
+ LIT(up->token.pos.file), up->token.pos.line, up->token.pos.column);
+ } else {
+ error(prev->token,
+ "Redeclaration of '%.*s' in this scope through 'using'\n"
+ "\tat %.*s(%td:%td)",
+ LIT(name),
+ LIT(up->token.pos.file), up->token.pos.line, up->token.pos.column);
+ }
} else {
if (pos == prev->token.pos) {
// NOTE(bill): Error should have been handled already
return false;
}
- error(prev->token,
- "Redeclaration of '%.*s' in this scope\n"
- "\tat %.*s(%td:%td)",
- LIT(name),
- LIT(pos.file), pos.line, pos.column);
+ if (found->flags & EntityFlag_Result) {
+ error(prev->token,
+ "Direct shadowing of the named return value '%.*s' in this scope\n"
+ "\tat %.*s(%td:%td)",
+ LIT(name),
+ LIT(pos.file), pos.line, pos.column);
+ } else {
+ error(prev->token,
+ "Redeclaration of '%.*s' in this scope\n"
+ "\tat %.*s(%td:%td)",
+ LIT(name),
+ LIT(pos.file), pos.line, pos.column);
+ }
}
return false;
}