Suspected Bug #7985
-
I was refactoring code earlier and introduced an Here's sample code that repros the issue: namespace ConsoleApp5
{
internal class Program
{
static void Main(string[] args)
{
var temp_1 = GetValue(0);
var temp_2 = GetValue(1);
}
public static int GetValue(GpioPort X)
{
return (int)(X);
}
}
public enum GpioPort
{
GpioA,
GpioB,
GpioC,
GpioD,
GpioE,
GpioF,
GpioG,
GpioH,
GpioI,
GpioJ,
}
} It will even accept zero if the namespace ConsoleApp5
{
internal class Program
{
static void Main(string[] args)
{
var temp_1 = GetValue(0);
}
public static GpioPort GetValue(GpioPort X)
{
return X;
}
}
public enum GpioPort
{
GpioA = 1,
GpioB,
GpioC,
GpioD,
GpioE,
GpioF,
GpioG,
GpioH,
GpioI,
GpioJ,
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
It's a known compiler deviation from standard: I believe it's for bug-to-bug compatibility. Issues about compiler behavior goes to roslyn repo. |
Beta Was this translation helpful? Give feedback.
-
Closing out as by design. The compiler, for legacy purposes, has always allowed the constant value 0 for any place an enum is used. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Yes, since 0 can always be produced with
default(T)
or new arrays.