Skip to content

[FIX] multi return values handling when lambda is used inside the function #113

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
Closed
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,15 +1086,12 @@ class cppfront
}

in_definite_init = is_definite_initialization(n.identifier);
if (in_synthesized_multi_return) {
printer.print_cpp2(".value()", n.position());
}
else if (!in_definite_init && !in_parameter_list) {
if (!in_definite_init && !in_parameter_list) {
if (auto decl = sema.get_declaration_of(*n.identifier);
is_local_name &&
decl &&
// note pointer equality: if we're not in the actual declaration of n.identifier
decl->identifier != n.identifier &&
(in_synthesized_multi_return || decl->identifier != n.identifier) &&
// and this variable was uninitialized
!decl->initializer &&
// and it's either a non-parameter or an out parameter
Expand All @@ -1104,6 +1101,9 @@ class cppfront
printer.print_cpp2(".value()", n.position());
}
}
else if (in_synthesized_multi_return) {
printer.print_cpp2(".value()", n.position());
}

if (add_std_move || add_std_forward) {
printer.print_cpp2(")", n.position());
Expand Down
6 changes: 4 additions & 2 deletions source/sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ class sema
{
auto const& decl = std::get<symbol::active::declaration>(i->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
&& decl.declaration->identifier // nullptr if lambda
) {
return nullptr;
}

Expand Down