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)
|
||||
|
|
18
compiler/test/fail_compilation/enum_auto_increment.d
Normal file
18
compiler/test/fail_compilation/enum_auto_increment.d
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation\enum_auto_increment.d(17): Error: cannot automatically assign value to enum member `enum_auto_increment.A2.d` because base type `A1` is an enum; provide an explicit value
|
||||
---
|
||||
*/
|
||||
|
||||
enum A1 : int
|
||||
{
|
||||
a,
|
||||
b,
|
||||
}
|
||||
|
||||
enum A2 : A1
|
||||
{
|
||||
c,
|
||||
d,
|
||||
}
|
|
@ -34,9 +34,7 @@ enum E1 : short
|
|||
/* https://issues.dlang.org/show_bug.cgi?id=14950
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail109.d(50): Error: cannot check `fail109.B.end` value for overflow
|
||||
fail_compilation/fail109.d(50): Error: comparison between different enumeration types `B` and `C`; If this behavior is intended consider using `std.conv.asOriginalType`
|
||||
fail_compilation/fail109.d(50): Error: enum member `fail109.B.end` initialization with `B.start+1` causes overflow for type `C`
|
||||
fail_compilation\fail109.d(48): Error: cannot automatically assign value to enum member `fail109.B.end` because base type `C` is an enum; provide an explicit value
|
||||
---
|
||||
*/
|
||||
enum C
|
||||
|
@ -53,10 +51,10 @@ enum B
|
|||
/* https://issues.dlang.org/show_bug.cgi?id=11849
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail109.d(72): Error: enum member `fail109.RegValueType1a.Unknown` is forward referenced looking for `.max`
|
||||
fail_compilation/fail109.d(79): Error: enum member `fail109.RegValueType1b.Unknown` is forward referenced looking for `.max`
|
||||
fail_compilation/fail109.d(84): Error: enum member `fail109.RegValueType2a.Unknown` is forward referenced looking for `.min`
|
||||
fail_compilation/fail109.d(91): Error: enum member `fail109.RegValueType2b.Unknown` is forward referenced looking for `.min`
|
||||
fail_compilation/fail109.d(70): Error: enum member `fail109.RegValueType1a.Unknown` is forward referenced looking for `.max`
|
||||
fail_compilation/fail109.d(77): Error: enum member `fail109.RegValueType1b.Unknown` is forward referenced looking for `.max`
|
||||
fail_compilation/fail109.d(82): Error: enum member `fail109.RegValueType2a.Unknown` is forward referenced looking for `.min`
|
||||
fail_compilation/fail109.d(89): Error: enum member `fail109.RegValueType2b.Unknown` is forward referenced looking for `.min`
|
||||
---
|
||||
*/
|
||||
|
||||
|
@ -94,7 +92,7 @@ enum RegValueType2b : DWORD
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail109.d(107): Error: enum member `fail109.d` initialization with `__anonymous.c+1` causes overflow for type `Q`
|
||||
fail_compilation/fail109.d(105): Error: enum member `fail109.d` initialization with `__anonymous.c+1` causes overflow for type `Q`
|
||||
---
|
||||
*/
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail98.d(17): Error: cannot implicitly convert expression `256` of type `int` to `E`
|
||||
fail_compilation/fail98.d(20): Error: cannot implicitly convert expression `256` of type `int` to `E`
|
||||
fail_compilation/fail98.d(21): Error: cannot automatically assign value to enum member `fail98.D3DTS_WORLD1` because base type `E` is an enum; provide an explicit value
|
||||
fail_compilation/fail98.d(22): Error: cannot automatically assign value to enum member `fail98.D3DTS_WORLD2` because base type `E` is an enum; provide an explicit value
|
||||
fail_compilation/fail98.d(23): Error: cannot automatically assign value to enum member `fail98.D3DTS_WORLD3` because base type `E` is an enum; provide an explicit value
|
||||
---
|
||||
*/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue