Skip to content

[FIX] Correct get_declaration_of not to skip first symbol #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions source/sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,24 @@ class sema

// Then look backward to find the first declaration of
// this name that is not deeper (in a nested scope)
for ( ; i != symbols.cbegin(); --i )
for (auto ri = std::make_reverse_iterator(i+1); ri != symbols.crend(); ++ri )
{
if (i->sym.index() == symbol::active::declaration && i->depth <= depth)
if (ri->sym.index() == symbol::active::declaration && ri->depth <= depth)
{
auto const& decl = std::get<symbol::active::declaration>(i->sym);
auto const& decl = std::get<symbol::active::declaration>(ri->sym);

// Don't look beyond the current function
assert(decl.declaration);
if (decl.declaration->type.index() == declaration_node::function) {
if (
decl.declaration->type.index() == declaration_node::function // Don't look beyond the current function
) {
return nullptr;
}

// If the name matches, this is it
if (decl.identifier && *decl.identifier == t) {
return &decl;
}
depth = i->depth;
depth = ri->depth;
}
}

Expand Down