[BUG] "Code block with parameters" lowers arguments without semicolon
Describe the bug Title.
To Reproduce Steps to reproduce the behavior:
- Sample code
main: () = {
(copy a: std::string, copy b: std::string) {
a = "Hello, ";
b = "World! ";
std::cout << a << b;
}
}
- Expected result - what you expected to happen
I would expect one of these to happen:
a. cppfront errors out and tells me that I need to initialize the parameters (if thats the intention)
b. They are lowered wrapped in the
deferred_initclass and the usual lifetime initialization semantics apply c. they are lowered as is, just with the extra; - Actual result/error outputs the following c++ code (redundant parts omitted):
auto main() -> int{
{
std::string a // <- whoops!
std::string b // <- whoops!
{
a = "Hello, ";
b = "World! ";
std::cout << cpp2::move(a) << cpp2::move(b);
}
}
}
Additional context I call this "Code block with parameters", but I don't know if there's a better name for them. I checked the documentation and they are referenced as "more RAII locally-scoped variables" and "local and immediate (aka 'let' in other languages)" which doesn't roll off the tongue too well 😛
~~side note - shouldn't a and b be declared inside the block? and there also seems to be an extra } at the end in the lowered cpp1. Think there's a little more wrong here than just the missing ; 😆~~
@zaucy It is inside the block. Does this formatting help you see what's happening?
auto main() -> int
{
{
std::string a
std::string b
{
a = "Hello, ";
b = "World! ";
std::cout << cpp2::move(a) << cpp2::move(b);
}
}
}
Here's a version with some context.
main: () = {
std::cout << "before";
(copy a: std::string, copy b: std::string) {
a = "Hello, ";
b = "World! ";
std::cout << a << b;
}
std::cout << "after";
}
auto main() -> int{
std::cout << "before";
{
std::string a
std::string b
{
a = "Hello, ";
b = "World! ";
std::cout << cpp2::move(a) << cpp2::move(b);
}
}
std::cout << "after";
}
Now, the formatting isn't the greatest, but the code is correct other than the semicolons missing.
Ah you're right my bad. I think the indentation is what threw me.
Yeah, that indentation could stand to be fixed.