6 days ago

On Thursday, 12 September 2024 at 12:14:17 UTC, ryuukk_ wrote:

>
struct Test
{
    int test;
}

struct Data
{
    Test[8] test;
}

void add(Data data)
{
}

extern(C) void main()
{
    add( Data(test: [ {test: 1}] ) );
}

You are passing a struct literal to add. A struct literal is an expression:
https://dlang.org/spec/struct.html#struct-literal

>

A struct literal consists of the name of the struct followed by a parenthesized named argument list

So [ {test: 1}] is parsed as an array literal (because it is an expression), not an array intializer. {test: 1} in expression context is parsed as an invalid function literal (because there's no semi-colon).

6 days ago

On Friday, 13 September 2024 at 10:55:11 UTC, Nick Treleaven wrote:

>

On Thursday, 12 September 2024 at 12:14:17 UTC, ryuukk_ wrote:

>
struct Test
{
    int test;
}

struct Data
{
    Test[8] test;
}

void add(Data data)
{
}

extern(C) void main()
{
    add( Data(test: [ {test: 1}] ) );
}

You are passing a struct literal to add. A struct literal is an expression:
https://dlang.org/spec/struct.html#struct-literal

>

A struct literal consists of the name of the struct followed by a parenthesized named argument list

So [ {test: 1}] is parsed as an array literal (because it is an expression), not an array intializer. {test: 1} in expression context is parsed as an invalid function literal (because there's no semi-colon).

This should be allowed, another DIP idea, if anyone still care about improving the language

1 2
Next ›   Last »