Skip to content

generate scalar select for records

Jordy Aaldering requested to merge 2408-record-scalar-select into develop

Closes #2408 (closed)

Using a scalar selection y[0] instead of y[[0]] produces an error.

struct Foo { int x; };

int main()
{
    y = [Foo{0}, Foo{1}, Foo{2}];
    z = y[0];
    return z.x;
}
No matching definition found for the application of "_MAIN::sel" to arguments ( int{0}, _MAIN::_struct_Foo[3])

A function sel(int[.] idx, struct Foo[*] arr) is being generated, but we should also generate:

struct Foo[*]
sel(int idx, struct Foo[*] arr)
{
    return sel([idx], arr);
}

Merge request reports