J
Jerry
I managed to narrow this down to a very simple expression. try this:
private void Bug()
{
bool b = false;
Test(3, (b || b) && b && !b);
}
private void Works()
{
bool b = true;
Test(3, (b || b) && b && !b);
}
private void Test(decimal v, bool b)
{
MessageBox.Show(v.ToString());
}
The value of the argument v in Test() is 0!
If you change the function Bug() and make bool b = true it works fine. I
checked the MSIL code and it appears that the compiler chocked on the
expression "(b || b) && b && !b" and silently truncated the previous
argument to bool (1 byte). Since the argument is a decimal it will show zero
because the truncation occurs on the decimal structure.
You can try this with any struct and any value as the first argument, the
compiler will always truncate the struct on the stack to 1 byte. If you try
with your own struct you will lose all the data after the first byte.
Strangely enough, if you remove the parenthesis "b || b && b && !b" is works
fine.
Plese don't focus on the expression, it's a simplification of a real
expression. The nastiest part is that there is no compiler error or warning,
it simply generates wrong MSIL code.
Is this a known bug? If not, how do I report this to Microsoft and to the
..NET team?
I tried in the past to report a bug with the shortcircuit operators specs
and compiler but didn't suceeded and the defect is still there.
I also tried with the latest service pack, the version shown in the .NET
Configuration module is version 1.1.4322.573.
private void Bug()
{
bool b = false;
Test(3, (b || b) && b && !b);
}
private void Works()
{
bool b = true;
Test(3, (b || b) && b && !b);
}
private void Test(decimal v, bool b)
{
MessageBox.Show(v.ToString());
}
The value of the argument v in Test() is 0!
If you change the function Bug() and make bool b = true it works fine. I
checked the MSIL code and it appears that the compiler chocked on the
expression "(b || b) && b && !b" and silently truncated the previous
argument to bool (1 byte). Since the argument is a decimal it will show zero
because the truncation occurs on the decimal structure.
You can try this with any struct and any value as the first argument, the
compiler will always truncate the struct on the stack to 1 byte. If you try
with your own struct you will lose all the data after the first byte.
Strangely enough, if you remove the parenthesis "b || b && b && !b" is works
fine.
Plese don't focus on the expression, it's a simplification of a real
expression. The nastiest part is that there is no compiler error or warning,
it simply generates wrong MSIL code.
Is this a known bug? If not, how do I report this to Microsoft and to the
..NET team?
I tried in the past to report a bug with the shortcircuit operators specs
and compiler but didn't suceeded and the defect is still there.
I also tried with the latest service pack, the version shown in the .NET
Configuration module is version 1.1.4322.573.