Wed 16 Feb 2005 07:23:05 AM UTC, original submission:
There is something wrong with the with the C# "as" and "is" operators, which seem to be compiled into CIL "isinst" instructions.
The following sequence prints "False" on Pnet but true on MS:
Array x = new string[1];
object[] y = x as object[];
Console.WriteLine(y == null );
I was trying to debug this myself, but I do not think that I have enough knowledge of the runtime engine internals. Also, I do not quite understand the correspondence between CVM instructions and similarly-named CIL instructions. I looked around to cvm_ptr.c and found this:
VMCASE(COP_ISINST):
{
/* Determine if the object on the stack top is an
instance of a particular class */
classInfo = CVM_ARG_PTR(ILClass *);
if(stacktop[-1].ptrValue != 0 &&
!ILClassInheritsFrom(GetObjectClass(stacktop[-1].ptrValue), classInfo))
{
stacktop[-1].ptrValue = 0;
}
MODIFY_PC_AND_STACK(CVM_LEN_PTR, 0);
}
However, according to the CIL spec, ISINST is supposed to attempt casting from source-type to result-type, and replace the top element of the stack with the result (if casting is successful) or null (if casting fails). I do not quite understand what it going on here because it seems as though the COP_ISINST case should look more like COP_CASTCLASS case.
I'm very confused about all this, but I think that someone more familiar with the runtime could fix it easily.
|