Skip to content

[BUG] Assignment of multiple return values #543

Open
@MaxSagebaum

Description

@MaxSagebaum

Describe the bug
Cpp2 does not seem to be able to capture multiple return values.

To Reproduce

  1. Sample code: https://cpp2.godbolt.org/z/eW66nP4eq
f: () -> (a: int, b: int) = {
    a = 1;
    b = 2;
}

main: (args) -> int = {
    i: int = 0;
    j: int = 0;

    // (i, j) = f();  // Option1: Parse error
    // i ,j = f();    // Option2: Parse error
    // {i, j} = f();  // Option3: Parse error
    // (s: int, t: int) = f(); // Option4: Parse error

    i = f();          // Obiously: Cpp compiler error

    return 0;
}
  1. Expected result:
    I would expect that either option 1,2 or 3 works.

  2. Actual result/error
    Option 1,2,3,4:

example.cpp2(6,23): error: ill-formed initializer (at '{')
example.cpp2(6,1): error: unexpected text at end of Cpp2 code section (at 'main')
example.cpp2(1,0): error: parse failed for section starting here

Additional context
I found this because I wanted to write a counterexample for #540

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions