Galin Iliev's blog

Software Architecture & Development

How to kill C# 2.0 compiler

I found an interesting article on CodeProject: How to crash MS C# Compiler!.

These are interesting issues. I am not a compiler guy (meaning I do not write compilers) but still it is interesting.

Case 1 - ++ operator overload
   1: public class TestClass
   2: {
   3: public static TestClass operator ++(TestClass ts)
   4: {
   5:     return new TestClass();
   6: }
   7: }
   8:  
   9: public class MyTest
  10: {
  11: public TestClass TestProperty
  12: {
  13:     get
  14:     {
  15:         return new TestClass();
  16:     }
  17: }
  18:  
  19: public void BadMethod()
  20: {
  21:     TestProperty++; // <-- PROBLEM HERE
  22: }
Case 2 - null array
   1: void SomeMethod()
   2: {
   3:     //const AnyType[] X = null;
   4:     const int[] X = null;
   5: }
Case 3 - Attribute with delegate
   1: public delegate void Proc();
   2: public class CrashAndBurnAttribute : System.Attribute
   3: {
   4:     public CrashAndBurnAttribute(Proc p)
   5:     { }
   6: }
   7:  
   8: public class CrashAndBurnClient
   9: {
  10:     [CrashAndBurn(delegate { return; })]
  11:     public void Foo()
  12:     {
  13:     }
  14: }

Who needs to write such statements!?

Comments (1) -

Loading