mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 21:21:48 +03:00
Fix dlang#18262 - Fix expected error message for enum auto-increment (#21067)
* Fix dlang#18262 - Resolved special enum case and other conflicts * Fix dlang#18262 - Resolved Special Enum case and failing test. * Fix dlang#18262 - Resolved special enum case and other failing tests
This commit is contained in:
parent
b390c7ec13
commit
c26b03fba2
4 changed files with 43 additions and 9 deletions
|
@ -524,6 +524,21 @@ void enumMemberSemantic(Scope* sc, EnumMember em)
|
|||
});
|
||||
|
||||
assert(emprev);
|
||||
|
||||
// New check: if the base type is an enum, auto-increment is not supported,
|
||||
// unless it is a special enum (for example, the C types like cpp_long/longlong).
|
||||
if (auto te = em.ed.memtype ? em.ed.memtype.isTypeEnum() : null)
|
||||
{
|
||||
if (!te.sym.isSpecial())
|
||||
{
|
||||
error(em.loc,
|
||||
"cannot automatically assign value to enum member `%s` because base type `%s` is an enum; provide an explicit value",
|
||||
em.toPrettyChars(), em.ed.memtype.toChars());
|
||||
return errorReturn();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (emprev.semanticRun < PASS.semanticdone) // if forward reference
|
||||
emprev.dsymbolSemantic(emprev._scope); // resolve it
|
||||
if (emprev.errors)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue