[Issue 24334] New: parameter name is ignored in invocation of struct constructor with default values
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jan 12 01:21:12 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24334
Issue ID: 24334
Summary: parameter name is ignored in invocation of struct
constructor with default values
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: jim at balter.name
struct Foo
{
this(int a, int b = 2, int c = 3)
{
imported!"std.stdio".writefln!"a=%s b=%s c=%s"(a, b, c);
}
}
void main()
{
auto foo = Foo(1, c: 99);
}
Expected output: a=1 b=2 c=99
Actual output: a=1 b=99 c=3
(This bug is dangerous, and quite shocking for a mature language.)
Note that the problem is only with a constructor. e.g, this works correctly:
struct Bar
{
static void bar(int a, int b = 2, int c = 3)
{
imported!"std.stdio".writefln!"a=%s b=%s c=%s"(a, b, c);
}
}
void main()
{
Bar.bar(1, c: 99);
}
output: a=1 b=2 c=99
--
More information about the Digitalmars-d-bugs
mailing list