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:
Samrendra Pratap Singh 2025-03-25 15:55:34 +05:30 committed by GitHub
parent b390c7ec13
commit c26b03fba2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 9 deletions

View file

@ -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)