Thread overview
[Issue 24334] parameter name is ignored in invocation of struct constructor with default values
Jan 12, 2024
Jim Balter
Jan 12, 2024
Nick Treleaven
Jan 12, 2024
Dennis
Jan 12, 2024
Nick Treleaven
Jan 12, 2024
Jim Balter
Jan 13, 2024
Nick Treleaven
January 12, 2024
https://issues.dlang.org/show_bug.cgi?id=24334

--- Comment #1 from Jim Balter <jim@balter.name> ---
P.S. The default constructor works correctly:

struct Foo
{
  int a, b = 2, c = 3;
}

void main()
{
  auto foo = Foo(1, c: 99);
  imported!"std.stdio".writefln!"a=%s b=%s c=%s"(foo.a, foo.b, foo.c);

}

output: a=1 b=2 c=99

--
January 12, 2024
https://issues.dlang.org/show_bug.cgi?id=24334

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #2 from Nick Treleaven <nick@geany.org> ---
> and quite shocking for a mature language

Named parameters are not mature, support began to be added in the April release last year. They were not mentioned in any changelogs and should have been behind a preview switch*. But the spec was updated, it should perhaps have a warning about stability.

* https://forum.dlang.org/post/bynneksajyfyadwndsbm@forum.dlang.org

--
January 12, 2024
https://issues.dlang.org/show_bug.cgi?id=24334

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dkorpel@live.nl
         Resolution|---                         |FIXED

--- Comment #3 from Dennis <dkorpel@live.nl> ---
This has been fixed by https://github.com/dlang/dmd/pull/15662

The output I get with dmd master is:

```
a=1 b=2 c=99
```

Which is your expected output. Please update your compiler version.

--
January 12, 2024
https://issues.dlang.org/show_bug.cgi?id=24334

--- Comment #4 from Nick Treleaven <nick@geany.org> ---
2.103.1 to 2.104.2: Success with output: a=1 b=99 c=3
Since      2.105.3: Success with output: a=1 b=2 c=99

--
January 12, 2024
https://issues.dlang.org/show_bug.cgi?id=24334

--- Comment #5 from Jim Balter <jim@balter.name> ---
> it should perhaps have a warning about stability

Or perhaps the compiler test suite should cover basic aspects of the feature.

--
January 13, 2024
https://issues.dlang.org/show_bug.cgi?id=24334

--- Comment #6 from Nick Treleaven <nick@geany.org> ---
> Or perhaps the compiler test suite should cover basic aspects of the feature.

It did by the time the spec mentioned named arguments.

--