I'm making a .NET-compatible compiler and today I have come across a very strange bug. I'm testing field getters and sometimes I get MissingFieldException with some of the built-in types' fields.
The fields I'm troubled with are:
MaxValueof all numericsMinValueof all numericsdouble.PositiveInfinitydouble.NegativeInfinitydouble.NaN
The code compiles fine: during compilation, the FieldInfo is found and a corresponding ldsfld is emitted. During the run phase, however, the aforementioned exception is being thrown. And this happens only for some fields: Type.EmptyTypes compiles and works just as expected!
I tried to investigate the IL-code which csc emits for those fields, but it does some optimizations and the program just pushes the actual value to the stack instead of calling the field. While this is, apparently, a more efficient way, for now I would like to keep my compiler as simple as possible.
Has anyone came across similar issues?