dmd/compiler/test/fail_compilation/fail10285.d
Nick Treleaven 59817ef96c
[dmd/parse] Refactor enum declaration (#15397)
* [dmd/parse] Refactor enum declaration

Tip: set ignore whitespace for diff.

Remove prevTOK.
Only use token loop for attributes.
"expected identifier after type" introduced in previous pull replaced
with "no identifier for declarator" for consistency.
Non-@ token "not a valid attribute" error replaced with "expected identifier".
"type only allowed if anonymous enum and no enum type" error was never
hit, this triggered "not a valid attribute" error instead.
No need to check `terror` as type will be null anyway.
"assignment must be preceded by an identifier" has been superceded by
other errors.
Make "enum declaration is invalid" error more informative.

* Add test for lone attribute

* Detect typed member with named enum for better error

* Add test for type error

* Avoid infinite loop

* Move 2 new tests to separate file; test `T @a b`
2023-07-19 13:01:40 +03:00

21 lines
757 B
D

/*
TEST_OUTPUT:
---
fail_compilation/fail10285.d(16): Error: no identifier for declarator `int`
fail_compilation/fail10285.d(17): Error: expected `,` or `=` after identifier, not `y`
fail_compilation/fail10285.d(17): Error: initializer required after `x` when type is specified
fail_compilation/fail10285.d(18): Error: no identifier for declarator `int`
fail_compilation/fail10285.d(18): Error: found `bool` when expecting `,`
fail_compilation/fail10285.d(19): Error: no identifier for declarator `j`
fail_compilation/fail10285.d(19): Error: found `int` when expecting `,`
fail_compilation/fail10285.d(21): Error: initializer required after `z` when type is specified
---
*/
enum
{
int = 5,
int x y,
int bool i = 3,
j int k = 3,
int z
}