hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.23k stars 224 forks source link

[BUG] "Code block with parameters" lowers arguments without semicolon #1135

Open DyXel opened 1 week ago

DyXel commented 1 week ago

Describe the bug Title.

To Reproduce Steps to reproduce the behavior:

  1. Sample code
    main: () = {
    (copy a: std::string, copy b: std::string) {
        a = "Hello, ";
        b = "World! ";
        std::cout << a << b;
    }
    }
  2. 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_init class and the usual lifetime initialization semantics apply c. they are lowered as is, just with the extra ;
  3. 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 😛