I'm not sure if this helps, but I've decided (for the first time) to dive
into the IL created for this. It seems that the probem is in the IL and not
the JIT (which i'd never understand anyway).
In trying to understand the IL code, I had to go to the msdn library to
figure it all out, so i copied a bit of the docs to make it easier. Note
near the bottom that a "goto" (whatever) is missing to jump over the
Console.WriteLine("A Is False!");
(I'm a veritable newbie at the IL thing, so I apologize if I'm stating the
obvious)
Scott
Here's the IL for Bug2.ctor():
..method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
//
// The following is a Release build with
// Optimization = True.
//
// IL documentation comments taken from:
//
http://msdn.microsoft.com/library/d...mreflectionemitopcodesclassbrfalse_stopic.asp
//
//
// Code size 50 (0x32)
.maxstack 1
.locals init (class ConsoleTest.Bug2/C V_0)
IL_0000: ldarg.0
// Calls the method indicated by the
// passed method descriptor, return
// value pushed onto stack
IL_0001: call instance void [mscorlib]System.Object::.ctor()
// Loads the argument at index 0 onto the evaluation stack.
IL_0006: ldarg.0
// A() pushes "true" onto stack
IL_0007: call instance bool ConsoleTest.Bug2::A()
// Transfers control to a target
// instruction if value is false,
// a null reference, or zero.
IL_000c: brfalse.s IL_0027
IL_000e: ldstr "A Is True!"
IL_0013: call void [mscorlib]System.Console::WriteLine(string)
// pushing an object reference (type O) onto the evaluation stack.
IL_0018: newobj instance void ConsoleTest.Bug2/C::.ctor()
// Pops the current value from top of stack
// and stores it in a the local variable
// list at index 0.
// (object "C" stored at 0.)
IL_001d: stloc.0
// Loads the local variable at index 0
// onto the evaluation stack
// (this is object "C")
IL_001e: ldloc.0
// Transfers control to a target
// instruction if value is false,
// a null reference, or zero.
// (since value is "C", it should be non-null, ie. true.)
IL_001f: brfalse.s IL_0027
// Loads the local variable at index 0
// onto the evaluation stack
// (this is object "C")
IL_0021: ldloc.0
// Calls a late-bound method on an
// object, pushing the return value
// onto the evaluation stack.
IL_0022: callvirt instance void [mscorlib]System.IDisposable:
ispose()
//
//-------------------------------------------------
// It seems that we're missing the "jump" over the
// "A Is False!" WriteLine
//-------------------------------------------------
//
IL_0027: ldstr "A Is False!"
IL_002c: call void [mscorlib]System.Console::WriteLine(string)
IL_0031: ret
} // end of method Bug2::.ctor