mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 21:21:48 +03:00

* Add named argument parsing * Refactor StructInitializer semantic to make it reusable * Move out `resolveStructLiteralNamedArgs` * Resolve named args in struct literal * Add tests * Check for errors returned by `resolveStructLiteralNamedArgs` * Expand names along with tuples * Update error messages in tests * Convert tabs to spaces in named arg test * Fix style of `resolveStructLiteralNamedArgs` * Clarify 'fixme' comment in expandTuples * Add example to `expandTuples` documentation * Update compiler/src/dmd/initsem.d Co-authored-by: Razvan Nitu <razvan.nitu1305@gmail.com> * Add overlapping initialization supplemental error to Struct Initializer * Improve "too many initializers" error message Co-authored-by: Razvan Nitu <razvan.nitu1305@gmail.com>
48 lines
1.2 KiB
D
48 lines
1.2 KiB
D
// REQUIRED_ARGS: -d
|
|
/*
|
|
TEST_OUTPUT:
|
|
---
|
|
fail_compilation/fail156.d(35): Error: overlapping initialization for field `x` and `y`
|
|
fail_compilation/fail156.d(35): `struct` initializers that contain anonymous unions must initialize only the first member of a `union`. All subsequent non-overlapping fields are default initialized
|
|
fail_compilation/fail156.d(42): Error: overlapping initialization for field `x` and `y`
|
|
fail_compilation/fail156.d(42): `struct` initializers that contain anonymous unions must initialize only the first member of a `union`. All subsequent non-overlapping fields are default initialized
|
|
---
|
|
*/
|
|
|
|
alias int myint;
|
|
|
|
struct S
|
|
{
|
|
int i;
|
|
union
|
|
{
|
|
int x = 2;
|
|
int y;
|
|
}
|
|
int j = 3;
|
|
myint k = 4;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
S s = S( 1, 5 );
|
|
assert(s.i == 1);
|
|
assert(s.x == 5);
|
|
assert(s.y == 5);
|
|
assert(s.j == 3);
|
|
assert(s.k == 4);
|
|
|
|
static S t = S( 1, 6, 6 );
|
|
assert(t.i == 1);
|
|
assert(t.x == 6);
|
|
assert(t.y == 6);
|
|
assert(t.j == 3);
|
|
assert(t.k == 4);
|
|
|
|
S u = S( 1, 5, 6 );
|
|
assert(u.i == 1);
|
|
assert(u.x == 5);
|
|
assert(u.y == 5);
|
|
assert(u.j == 3);
|
|
assert(u.k == 4);
|
|
}
|