Skip to content

Commit 0a8dcf6

Browse files
authored
Modify the scope_depth for variables in lambdas (#350)
If variable parent is a function without the name the scope_depth is increased by 1. Not to be mixed with variables from scope where lambda was created.
1 parent 47fbb70 commit 0a8dcf6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

source/sema.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,9 @@ class sema
971971
|| n.pass == passing_style::forward
972972
)
973973
{
974-
symbols.emplace_back( scope_depth, declaration_sym( true, n.declaration.get(), n.declaration->name(), n.declaration->initializer.get(), &n));
974+
// Handle variables in unnamed functions. For such cases scope_depth is increased by +1
975+
auto depth = scope_depth + ((n.declaration->parent_is_function() && n.declaration->parent_declaration->name() == nullptr) ? 1 : 0 );
976+
symbols.emplace_back( depth, declaration_sym( true, n.declaration.get(), n.declaration->name(), n.declaration->initializer.get(), &n));
975977
}
976978
}
977979

0 commit comments

Comments
 (0)