Merge pull request #4998 from kumpera/fix_56684
[mono.git] / mcs / tests / gtest-143.cs
index 6a9f561c2e55327d6643f2592e4cc4ec3434aa50..808bbca599d36185126d52dca65aa2877efdc39c 100644 (file)
@@ -2,6 +2,25 @@ using System;
 
 class X
 {
+       static int counter;
+       static int Index ()
+       {
+               if (counter++ != 0)
+                       throw new ApplicationException ();
+               
+               return 1;
+       }
+       
+       int? indexer;
+       int? this [int index] {
+               get {
+                       return indexer;
+               }
+               set {
+                       indexer = value;
+               }
+       }       
+       
        static int Test ()
        {
                int? a = 5;
@@ -31,11 +50,44 @@ class X
                        return 6;
                if (d != 15)
                        return 7;
+               
+               var s = new short?[] { 3, 2, 1 };
+               counter = 0;
+               var r = s [Index ()]++;
+               if (counter != 1)
+                       return 8;
+               
+               if (r != 2)
+                       return 9;
+               
+               if (s[1] != 3)
+                       return 10;
+
+               counter = 0;
+               s [Index ()]++;
+               if (counter != 1)
+                       return 11;
+               
+               if (s[1] != 4)
+                       return 12;
+                       
+               X x = new X ();
+               x.indexer = 6;
+               counter = 0;
+               var r2 = x[Index ()]--;
+               if (counter != 1)
+                       return 13;
+                       
+               if (r2 != 6)
+                       return 14;
+               
+               if (x.indexer != 5)
+                       return 15;
 
                return 0;
        }
 
-       static int Main ()
+       public static int Main ()
        {
                int result = Test ();
                if (result != 0)