Skip to content

Commit 99fd644

Browse files
committed
Correct get_declaration_of not to skip first symbol
When lookig backward there for loop will never check symbols.cbegin() as it is excluded by `i != symbols.cbegin()` condition. Change normal iterators to `std::reverse_iterator`.
1 parent b1754db commit 99fd644

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

source/sema.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,21 @@ class sema
236236
++i;
237237
}
238238

239-
while (i == symbols.cend() || !i->start) {
240-
--i;
239+
auto ri = std::reverse_iterator(i);
240+
241+
while (ri == symbols.crbegin() || !ri->start) {
242+
++ri;
241243
}
242244

243-
auto depth = i->depth;
245+
auto depth = ri->depth;
244246

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

253255
// Don't look beyond the current function
254256
assert(decl.declaration);
@@ -260,7 +262,7 @@ class sema
260262
if (decl.identifier && *decl.identifier == t) {
261263
return &decl;
262264
}
263-
depth = i->depth;
265+
depth = ri->depth;
264266
}
265267
}
266268

0 commit comments

Comments
 (0)