aboutsummaryrefslogtreecommitdiff
path: root/src/checker.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-10-04 12:41:33 +0100
committergingerBill <bill@gingerbill.org>2021-10-04 12:41:33 +0100
commita463609e4c6753f520d11a6d9180cb720c4eeb38 (patch)
treea9fb43628eae8cda40e8fa8d4a1e3d2bf0073fda /src/checker.cpp
parente05a30576456bf7165aaad8d975539e6326d09a5 (diff)
If an entity is inserted into a scope already exists by the same name, it will not report as an error any more
Diffstat (limited to 'src/checker.cpp')
-rw-r--r--src/checker.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index e1ccf5d96..334495ea6 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -415,20 +415,28 @@ Entity *scope_insert_with_name(Scope *s, String const &name, Entity *entity) {
return nullptr;
}
StringHashKey key = string_hash_string(name);
+ Entity **found = nullptr;
+ Entity *result = nullptr;
mutex_lock(&s->mutex);
defer (mutex_unlock(&s->mutex));
-
- Entity **found = string_map_get(&s->elements, key);
+
+ found = string_map_get(&s->elements, key);
if (found) {
- return *found;
+ if (entity != *found) {
+ result = *found;
+ }
+ goto end;
}
if (s->parent != nullptr && (s->parent->flags & ScopeFlag_Proc) != 0) {
- Entity **found = string_map_get(&s->parent->elements, key);
+ found = string_map_get(&s->parent->elements, key);
if (found) {
if ((*found)->flags & EntityFlag_Result) {
- return *found;
+ if (entity != *found) {
+ result = *found;
+ }
+ goto end;
}
}
}
@@ -437,7 +445,8 @@ Entity *scope_insert_with_name(Scope *s, String const &name, Entity *entity) {
if (entity->scope == nullptr) {
entity->scope = s;
}
- return nullptr;
+end:;
+ return result;
}
Entity *scope_insert(Scope *s, Entity *entity) {