When I use the following code:
using System;
namespace Foo {
[Flags]
public enum Bar : ulong {
None = 0x0000000000000000,
A = 0x8000000000000000,
B = 0x0000000000000001L | A,
C = 0x0000000000000002L | B,
D = 0x0000000000000004L | A,
All = A | B | C | D
}
}
The mono compiler crashes. Is this due to a semantical error (something that is not allowed in the language), but is unnoticed by the compiler or is this a compiler-bug?
Version: Mono 2.10.8.1
I've filed a bug report at bugzilla (https://bugzilla.xamarin.com/show_bug.cgi?id=15801)
From the C# language spec, section 14.3:
The associated value of an enum member may not, directly or indirectly, use the value of its own associated enum member. Other than this circularity restriction, enum member initializers may freely refer to other enum member initializers, regardless of their textual position.
So your code should be correct (as it has already been suggested in the comments), and thus it should be a compiler bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With