The following code yields error CS0131: "The left-hand side of an assignment
must be a variable, property or indexer": (new int())++;
However, when using a class with a custom operator++, an
InvalidProgramException is thrown. I assume this is a compiler bug of some
sort, and that error CS0131 should be raised instead.
Here's a complete program that illustrates the issue:
namespace ErrorTest
{
class Program
{
public Program(int _) { i = _; }
public static Program operator ++(Program b) {
Program tmp = new Program(b.i);
tmp.i++;
return tmp;
}
public int i;
static void Main(string[] args) {
(new Program(0))++;
}
}
}
Running PEVerify on the above code yields a stack underflow in Main at
Offset 0x1. The dissassembly of Main is as follows:
..method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 7 (0x7)
.maxstack 8
IL_0000: nop
IL_0001: call class ErrorTest.Program
ErrorTest.Program::op_Increment(class ErrorTest.Program)
IL_0006: ret
} // end of method Program::Main
This was all experienced using VC# 2005 Standard.
DZJr