Update mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/RelaxngPattern.cs
[mono.git] / mono / mini / generics.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Runtime.CompilerServices;
5
6 class Tests {
7
8         struct TestStruct {
9                 public int i;
10                 public int j;
11
12                 public TestStruct (int i, int j) {
13                         this.i = i;
14                         this.j = j;
15                 }
16         }
17
18         class Enumerator <T> : MyIEnumerator <T> {
19                 T MyIEnumerator<T>.Current {
20                         get {
21                                 return default(T);
22                         }
23                 }
24
25                 bool MyIEnumerator<T>.MoveNext () {
26                         return true;
27                 }
28         }
29
30         class Comparer <T> : IComparer <T> {
31                 bool IComparer<T>.Compare (T x, T y) {
32                         return true;
33                 }
34         }
35
36         static int Main (string[] args)
37         {
38                 return TestDriver.RunTests (typeof (Tests), args);
39         }
40
41         public static int test_1_nullable_unbox ()
42         {
43                 return Unbox<int?> (1).Value;
44         }
45
46         public static int test_1_nullable_unbox_null ()
47         {
48                 return Unbox<int?> (null).HasValue ? 0 : 1;
49         }
50
51         public static int test_1_nullable_box ()
52         {
53                 return (int) Box<int?> (1);
54         }
55
56         public static int test_1_nullable_box_null ()
57         {
58                 return Box<int?> (null) == null ? 1 : 0;
59         }
60
61         public static int test_1_isinst_nullable ()
62         {
63                 object o = 1;
64                 return (o is int?) ? 1 : 0;
65         }
66
67         public static int test_1_nullable_unbox_vtype ()
68         {
69                 return Unbox<TestStruct?> (new TestStruct (1, 2)).Value.i;
70         }
71
72         public static int test_1_nullable_unbox_null_vtype ()
73         {
74                 return Unbox<TestStruct?> (null).HasValue ? 0 : 1;
75         }
76
77         public static int test_1_nullable_box_vtype ()
78         {
79                 return ((TestStruct)(Box<TestStruct?> (new TestStruct (1, 2)))).i;
80         }
81
82         public static int test_1_nullable_box_null_vtype ()
83         {
84                 return Box<TestStruct?> (null) == null ? 1 : 0;
85         }
86
87         public static int test_1_isinst_nullable_vtype ()
88         {
89                 object o = new TestStruct (1, 2);
90                 return (o is TestStruct?) ? 1 : 0;
91         }
92
93         public static int test_0_nullable_normal_unbox ()
94         {
95                 int? i = 5;
96
97                 object o = i;
98                 // This uses unbox instead of unbox_any
99                 int? j = (int?)o;
100
101                 if (j != 5)
102                         return 1;
103
104                 return 0;
105         }
106
107         public static void stelem_any<T> (T[] arr, T elem) {
108                 arr [0] = elem;
109         }
110
111         public static T ldelem_any<T> (T[] arr) {
112                 return arr [0];
113         }
114
115         public static int test_1_ldelem_stelem_any_int () {
116                 int[] arr = new int [3];
117                 stelem_any (arr, 1);
118
119                 return ldelem_any (arr);
120         }
121
122         public static T return_ref<T> (ref T t) {
123                 return t;
124         }
125
126         public static T ldelema_any<T> (T[] arr) {
127                 return return_ref<T> (ref arr [0]);
128         }
129
130         public static int test_0_ldelema () {
131                 string[] arr = new string [1];
132
133                 arr [0] = "Hello";
134
135                 if (ldelema_any <string> (arr) == "Hello")
136                         return 0;
137                 else
138                         return 1;
139         }
140
141         public static T[,] newarr_multi<T> () {
142                 return new T [1, 1];
143         }
144
145         public static int test_0_newarr_multi_dim () {
146                 return newarr_multi<string> ().GetType () == typeof (string[,]) ? 0 : 1;
147         }
148
149         interface ITest
150         {
151                 void Foo<T> ();
152         }
153
154         public static int test_0_iface_call_null_bug_77442 () {
155                 ITest test = null;
156
157                 try {
158                         test.Foo<int> ();
159                 }
160                 catch (NullReferenceException) {
161                         return 0;
162                 }
163                 
164                 return 1;
165         }
166
167         public static int test_18_ldobj_stobj_generics () {
168                 GenericClass<int> t = new GenericClass <int> ();
169                 int i = 5;
170                 int j = 6;
171                 return t.ldobj_stobj (ref i, ref j) + i + j;
172         }
173
174         public static int test_5_ldelem_stelem_generics () {
175                 GenericClass<TestStruct> t = new GenericClass<TestStruct> ();
176
177                 TestStruct s = new TestStruct (5, 5);
178                 return t.ldelem_stelem (s).i;
179         }
180
181         public static int test_0_constrained_vtype_box () {
182                 GenericClass<TestStruct> t = new GenericClass<TestStruct> ();
183
184                 return t.toString (new TestStruct ()) == "Tests+TestStruct" ? 0 : 1;
185         }
186
187         public static int test_0_constrained_vtype () {
188                 GenericClass<int> t = new GenericClass<int> ();
189
190                 return t.toString (1234) == "1234" ? 0 : 1;
191         }
192
193         public static int test_0_constrained_reftype () {
194                 GenericClass<String> t = new GenericClass<String> ();
195
196                 return t.toString ("1234") == "1234" ? 0 : 1;
197         }
198
199         public static int test_0_box_brtrue_optimizations () {
200                 if (IsNull<int>(5))
201                         return 1;
202
203                 if (!IsNull<object>(null))
204                         return 1;
205
206                 return 0;
207         }
208
209         [Category ("!FULLAOT")]
210         public static int test_0_generic_get_value_optimization_int () {
211                 int[] x = new int[] {100, 200};
212
213                 if (GenericClass<int>.Z (x, 0) != 100)
214                         return 2;
215
216                 if (GenericClass<int>.Z (x, 1) != 200)
217                         return 3;
218
219                 return 0;
220         }
221
222         public static int test_0_generic_get_value_optimization_vtype () {
223                 TestStruct[] arr = new TestStruct[] { new TestStruct (100, 200), new TestStruct (300, 400) };
224                 IEnumerator<TestStruct> enumerator = GenericClass<TestStruct>.Y (arr);
225                 TestStruct s;
226                 int sum = 0;
227                 while (enumerator.MoveNext ()) {
228                         s = enumerator.Current;
229                         sum += s.i + s.j;
230                 }
231
232                 if (sum != 1000)
233                         return 1;
234
235                 s = GenericClass<TestStruct>.Z (arr, 0);
236                 if (s.i != 100 || s.j != 200)
237                         return 2;
238
239                 s = GenericClass<TestStruct>.Z (arr, 1);
240                 if (s.i != 300 || s.j != 400)
241                         return 3;
242
243                 return 0;
244         }
245
246         public static int test_0_nullable_ldflda () {
247                 return GenericClass<string>.BIsAClazz == false ? 0 : 1;
248         }
249
250         public struct GenericStruct<T> {
251                 public T t;
252
253                 public GenericStruct (T t) {
254                         this.t = t;
255                 }
256         }
257
258         public class GenericClass<T> {
259                 public T t;
260
261                 public GenericClass (T t) {
262                         this.t = t;
263                 }
264
265                 public GenericClass () {
266                 }
267
268                 public T ldobj_stobj (ref T t1, ref T t2) {
269                         t1 = t2;
270                         T t = t1;
271
272                         return t;
273                 }
274
275                 public T ldelem_stelem (T t) {
276                         T[] arr = new T [10];
277                         arr [0] = t;
278
279                         return arr [0];
280                 }
281
282                 public String toString (T t) {
283                         return t.ToString ();
284                 }
285
286                 public static IEnumerator<T> Y (IEnumerable <T> x)
287                 {
288                         return x.GetEnumerator ();
289                 }
290
291                 public static T Z (IList<T> x, int index)
292                 {
293                         return x [index];
294                 }
295
296         protected static T NullB = default(T);       
297         private static Nullable<bool>  _BIsA = null;
298         public static bool BIsAClazz {
299             get {
300                 _BIsA = false;
301                 return _BIsA.Value;
302             }
303         }
304         }
305
306         public class MRO : MarshalByRefObject {
307                 public GenericStruct<int> struct_field;
308                 public GenericClass<int> class_field;
309         }
310
311         public static int test_0_ldfld_stfld_mro () {
312                 MRO m = new MRO ();
313                 GenericStruct<int> s = new GenericStruct<int> (5);
314                 // This generates stfld
315                 m.struct_field = s;
316
317                 // This generates ldflda
318                 if (m.struct_field.t != 5)
319                         return 1;
320
321                 // This generates ldfld
322                 GenericStruct<int> s2 = m.struct_field;
323                 if (s2.t != 5)
324                         return 2;
325
326                 if (m.struct_field.t != 5)
327                         return 3;
328
329                 m.class_field = new GenericClass<int> (5);
330                 if (m.class_field.t != 5)
331                         return 4;
332
333                 return 0;
334         }
335
336         // FIXME:
337         [Category ("!FULLAOT")]
338     public static int test_0_generic_virtual_call_on_vtype_unbox () {
339                 object o = new Object ();
340         IFoo h = new Handler(o);
341
342         if (h.Bar<object> () != o)
343                         return 1;
344                 else
345                         return 0;
346     }
347
348         public static int test_0_box_brtrue_opt () {
349                 Foo<int> f = new Foo<int> (5);
350
351                 f [123] = 5;
352
353                 return 0;
354         }
355
356         public static int test_0_box_brtrue_opt_regress_81102 () {
357                 if (new Foo<int>(5).ToString () == "null")
358                         return 0;
359                 else
360                         return 1;
361         }
362
363         struct S {
364                 public int i;
365         }
366
367         public static int test_0_ldloca_initobj_opt () {
368                 if (new Foo<S> (new S ()).get_default ().i != 0)
369                         return 1;
370                 if (new Foo<object> (null).get_default () != null)
371                         return 2;
372                 return 0;
373         }
374
375         public static int test_0_variance_reflection () {
376                 // covariance on IEnumerator
377                 if (!typeof (MyIEnumerator<object>).IsAssignableFrom (typeof (MyIEnumerator<string>)))
378                         return 1;
379                 // covariance on IEnumerator and covariance on arrays
380                 if (!typeof (MyIEnumerator<object>[]).IsAssignableFrom (typeof (MyIEnumerator<string>[])))
381                         return 2;
382                 // covariance and implemented interfaces
383                 if (!typeof (MyIEnumerator<object>).IsAssignableFrom (typeof (Enumerator<string>)))
384                         return 3;
385
386                 // contravariance on IComparer
387                 if (!typeof (IComparer<string>).IsAssignableFrom (typeof (IComparer<object>)))
388                         return 4;
389                 // contravariance on IComparer, contravariance on arrays
390                 if (!typeof (IComparer<string>[]).IsAssignableFrom (typeof (IComparer<object>[])))
391                         return 5;
392                 // contravariance and interface inheritance
393                 if (!typeof (IComparer<string>[]).IsAssignableFrom (typeof (IKeyComparer<object>[])))
394                         return 6;
395                 return 0;
396         }
397
398         public static int test_0_ldvirtftn_generic_method () {
399                 new Tests ().ldvirtftn<string> ();              
400
401                 return the_type == typeof (string) ? 0 : 1;
402         }
403
404         public static int test_0_throw_dead_this () {
405         new Foo<string> ("").throw_dead_this ();
406                 return 0;
407         }
408
409         struct S<T> {}
410
411         public static int test_0_inline_infinite_polymorphic_recursion () {
412            f<int>(0);
413
414                    return 0;
415         }
416
417         private static void f<T>(int i) {
418                 if(i==42) f<S<T>>(i);
419         }
420
421         // This cannot be made to work with full-aot, since there it is impossible to
422         // statically determine that Foo<string>.Bar <int> is needed, the code only
423         // references IFoo.Bar<int>
424         [Category ("!FULLAOT")]
425         public static int test_0_generic_virtual_on_interfaces () {
426                 Foo<string>.count1 = 0;
427                 Foo<string>.count2 = 0;
428                 Foo<string>.count3 = 0;
429
430                 IFoo f = new Foo<string> ("");
431                 for (int i = 0; i < 1000; ++i) {
432                         f.Bar <int> ();
433                         f.Bar <string> ();
434                         f.NonGeneric ();
435                 }
436
437                 if (Foo<string>.count1 != 1000)
438                         return 1;
439                 if (Foo<string>.count2 != 1000)
440                         return 2;
441                 if (Foo<string>.count3 != 1000)
442                         return 3;
443
444                 VirtualInterfaceCallFromGenericMethod<long> (f);
445
446                 return 0;
447         }
448
449         public static int test_0_generic_virtual_on_interfaces_ref () {
450                 Foo<string>.count1 = 0;
451                 Foo<string>.count2 = 0;
452                 Foo<string>.count3 = 0;
453                 Foo<string>.count4 = 0;
454
455                 IFoo f = new Foo<string> ("");
456                 for (int i = 0; i < 1000; ++i) {
457                         f.Bar <string> ();
458                         f.Bar <object> ();
459                         f.NonGeneric ();
460                 }
461
462                 if (Foo<string>.count2 != 1000)
463                         return 2;
464                 if (Foo<string>.count3 != 1000)
465                         return 3;
466                 if (Foo<string>.count4 != 1000)
467                         return 4;
468
469                 return 0;
470         }
471
472         //repro for #505375
473         [Category ("!FULLAOT")]
474         public static int test_2_cprop_bug () {
475                 int idx = 0;
476                 int a = 1;
477                 var cmp = System.Collections.Generic.Comparer<int>.Default ;
478                 if (cmp.Compare (a, 0) > 0)
479                         a = 0;
480                 do { idx++; } while (cmp.Compare (idx - 1, a) == 0);
481                 return idx;
482         }
483
484         enum MyEnumUlong : ulong {
485                 Value_2 = 2
486         }
487
488         public static int test_0_regress_550964_constrained_enum_long () {
489         MyEnumUlong a = MyEnumUlong.Value_2;
490         MyEnumUlong b = MyEnumUlong.Value_2;
491
492         return Pan (a, b) ? 0 : 1;
493         }
494
495     static bool Pan<T> (T a, T b)
496     {
497         return a.Equals (b);
498     }
499
500         public class XElement {
501                 public string Value {
502                         get; set;
503                 }
504         }
505
506         public static int test_0_fullaot_linq () {
507                 var allWords = new XElement [] { new XElement { Value = "one" } };
508                 var filteredWords = allWords.Where(kw => kw.Value.StartsWith("T"));
509                 return filteredWords.Count ();
510         }
511
512         public static int test_0_fullaot_comparer_t () {
513                 var l = new SortedList <TimeSpan, int> ();
514                 return l.Count;
515         }
516
517         public static int test_0_fullaot_comparer_t_2 () {
518                 var l = new Dictionary <TimeSpan, int> ();
519                 return l.Count;
520         }
521
522         static void enumerate<T> (IEnumerable<T> arr) {
523                 foreach (var o in arr)
524                         ;
525                 int c = ((ICollection<T>)arr).Count;
526         }
527
528         /* Test that treating arrays as generic collections works with full-aot */
529         public static int test_0_fullaot_array_wrappers () {
530                 Tests[] arr = new Tests [10];
531                 enumerate<Tests> (arr);
532                 return 0;
533         }
534
535         static int cctor_count = 0;
536
537     public abstract class Beta<TChanged> 
538     {           
539         static Beta()
540         {
541                         cctor_count ++;
542         }
543     }   
544     
545     public class Gamma<T> : Beta<T> 
546     {   
547         static Gamma()
548         {
549         }
550     }
551
552         // #519336    
553         public static int test_2_generic_class_init_gshared_ctor () {
554                 new Gamma<object>();
555                 new Gamma<string>();
556
557                 return cctor_count;
558         }
559
560         static int cctor_count2 = 0;
561
562         class ServiceController<T> {
563                 static ServiceController () {
564                         cctor_count2 ++;
565                 }
566
567                 public ServiceController () {
568                 }
569         }
570
571         static ServiceController<T> Create<T>() {
572                 return new ServiceController<T>();
573         }
574
575         // #631409
576         public static int test_2_generic_class_init_gshared_ctor_from_gshared () {
577                 Create<object> ();
578                 Create<string> ();
579
580                 return cctor_count2;
581         }
582
583         public static Type get_type<T> () {
584                 return typeof (T);
585         }
586
587         public static int test_0_gshared_delegate_rgctx () {
588                 Func<Type> t = new Func<Type> (get_type<string>);
589
590                 if (t () == typeof (string))
591                         return 0;
592                 else
593                         return 1;
594         }
595
596         // Creating a delegate from a generic method from gshared code
597         public static int test_0_gshared_delegate_from_gshared () {
598                 if (gshared_delegate_from_gshared <object> () != 0)
599                         return 1;
600                 if (gshared_delegate_from_gshared <string> () != 0)
601                         return 2;
602                 return 0;
603         }
604
605         public static int gshared_delegate_from_gshared <T> () {
606                 Func<Type> t = new Func<Type> (get_type<T>);
607
608                 return t () == typeof (T) ? 0 : 1;
609         }
610
611         public static int test_0_marshalbyref_call_from_gshared_virt_elim () {
612                 /* Calling a virtual method from gshared code which is changed to a nonvirt call */
613                 Class1<object> o = new Class1<object> ();
614                 o.Do (new Class2<object> ());
615                 return 0;
616         }
617
618         class Pair<TKey, TValue> {
619                 public static KeyValuePair<TKey, TValue> make_pair (TKey key, TValue value)
620                         {
621                                 return new KeyValuePair<TKey, TValue> (key, value);
622                         }
623
624                 public delegate TRet Transform<TRet> (TKey key, TValue value);
625         }
626
627         public static int test_0_bug_620864 () {
628                 var d = new Pair<string, Type>.Transform<KeyValuePair<string, Type>> (Pair<string, Type>.make_pair);
629
630                 var p = d ("FOO", typeof (int));
631                 if (p.Key != "FOO" || p.Value != typeof (int))
632                         return 1;
633
634                 return 0;
635         }
636
637
638         struct RecStruct<T> {
639                 public void foo (RecStruct<RecStruct<T>> baz) {
640                 }
641         }
642
643         public static int test_0_infinite_generic_recursion () {
644                 // Check that the AOT compile can deal with infinite generic recursion through
645                 // parameter types
646                 RecStruct<int> bla;
647
648                 return 0;
649         }
650
651         struct FooStruct {
652         }
653
654         bool IsNull2 <T> (object value) where T : struct {
655                 T? item = (T?) value;
656
657                 if (item.HasValue)
658                         return false;
659
660                 return true;
661         }
662
663         public static int test_0_full_aot_nullable_unbox_from_gshared_code () {
664                 if (!new Tests ().IsNull2<FooStruct> (null))
665                         return 1;
666                 if (new Tests ().IsNull2<FooStruct> (new FooStruct ()))
667                         return 2;
668                 return 0;
669         }
670
671         public static int test_0_partial_sharing () {
672                 if (PartialShared1 (new List<string> (), 1) != typeof (string))
673                         return 1;
674                 if (PartialShared1 (new List<Tests> (), 1) != typeof (Tests))
675                         return 2;
676                 if (PartialShared2 (new List<string> (), 1) != typeof (int))
677                         return 3;
678                 if (PartialShared2 (new List<Tests> (), 1) != typeof (int))
679                         return 4;
680                 return 0;
681         }
682
683         public static int test_6_partial_sharing_linq () {
684                 var messages = new List<Message> ();
685
686                 messages.Add (new Message () { MessageID = 5 });
687                 messages.Add (new Message () { MessageID = 6 });
688
689                 return messages.Max(i => i.MessageID);
690         }
691
692         public static int test_0_partial_shared_method_in_nonshared_class () {
693                 var c = new Class1<double> ();
694                 return (c.Foo<string> (5).GetType () == typeof (Class1<string>)) ? 0 : 1;
695         }
696
697         class Message {
698                 public int MessageID {
699                         get; set;
700                 }
701         }
702
703         public static Type PartialShared1<T, K> (List<T> list, K k) {
704                 return typeof (T);
705         }
706
707         public static Type PartialShared2<T, K> (List<T> list, K k) {
708                 return typeof (K);
709         }
710
711     public class Class1<T> {
712                 public virtual void Do (Class2<T> t) {
713                         t.Foo ();
714                 }
715
716                 public virtual object Foo<U> (T t) {
717                         return new Class1<U> ();
718                 }
719         }
720
721         public interface IFace1<T> {
722                 void Foo ();
723         }
724
725         public class Class2<T> : MarshalByRefObject, IFace1<T> {
726                 public void Foo () {
727                 }
728         }
729
730
731
732         public static void VirtualInterfaceCallFromGenericMethod <T> (IFoo f) {
733                 f.Bar <T> ();
734         }
735
736         public static Type the_type;
737
738         public void ldvirtftn<T> () {
739                 Foo <T> binding = new Foo <T> (default (T));
740
741                 binding.GenericEvent += event_handler;
742                 binding.fire ();
743         }
744
745         public virtual void event_handler<T> (Foo<T> sender) {
746                 the_type = typeof (T);
747         }
748
749         public interface IFoo {
750                 void NonGeneric ();
751                 object Bar<T>();
752         }
753
754         public class Foo<T1> : IFoo
755         {
756                 public Foo(T1 t1)
757                 {
758                         m_t1 = t1;
759                 }
760                 
761                 public override string ToString()
762                 {
763                         return Bar(m_t1 == null ? "null" : "null");
764                 }
765
766                 public String Bar (String s) {
767                         return s;
768                 }
769
770                 public int this [T1 key] {
771                         set {
772                                 if (key == null)
773                                         throw new ArgumentNullException ("key");
774                         }
775                 }
776
777                 public void throw_dead_this () {
778                         try {
779                                 new SomeClass().ThrowAnException();
780                         }
781                         catch {
782                         }
783                 }
784
785                 public T1 get_default () {
786                         return default (T1);
787                 }
788                 
789                 readonly T1 m_t1;
790
791                 public delegate void GenericEventHandler (Foo<T1> sender);
792
793                 public event GenericEventHandler GenericEvent;
794
795                 public void fire () {
796                         GenericEvent (this);
797                 }
798
799                 public static int count1, count2, count3, count4;
800
801                 public void NonGeneric () {
802                         count3 ++;
803                 }
804
805                 public object Bar <T> () {
806                         if (typeof (T) == typeof (int))
807                                 count1 ++;
808                         else if (typeof (T) == typeof (string))
809                                 count2 ++;
810                         else if (typeof (T) == typeof (object))
811                                 count4 ++;
812                         return null;
813                 }
814         }
815
816         public class SomeClass {
817                 public void ThrowAnException() {
818                         throw new Exception ("Something went wrong");
819                 }
820         }               
821
822         struct Handler : IFoo {
823                 object o;
824
825                 public Handler(object o) {
826                         this.o = o;
827                 }
828
829                 public void NonGeneric () {
830                 }
831
832                 public object Bar<T>() {
833                         return o;
834                 }
835         }
836
837         static bool IsNull<T> (T t)
838         {
839                 if (t == null)
840                         return true;
841                 else
842                         return false;
843         }
844
845         static object Box<T> (T t)
846         {
847                 return t;
848         }
849         
850         static T Unbox <T> (object o) {
851                 return (T) o;
852         }
853
854         interface IDefaultRetriever
855         {
856                 T GetDefault<T>();
857         }
858
859         class DefaultRetriever : IDefaultRetriever
860         {
861                 [MethodImpl(MethodImplOptions.Synchronized)]
862                 public T GetDefault<T>()
863                 {
864                         return default(T);
865                 }
866         }
867
868         [Category ("!FULLAOT")]
869         public static int test_0_regress_668095_synchronized_gshared () {
870                 return DoSomething (new DefaultRetriever ());
871         }
872
873     static int DoSomething(IDefaultRetriever foo) {
874                 int result = foo.GetDefault<int>();
875                 return result;
876         }
877
878         class Response {
879         }
880
881         public static int test_0_687865_isinst_with_cache_wrapper () {
882                 object o = new object ();
883                 if (o is Action<IEnumerable<Response>>)
884                         return 1;
885                 else
886                         return 0;
887         }
888
889         enum DocType {
890                 One,
891                 Two,
892                 Three
893         }
894
895         class Doc {
896                 public string Name {
897                         get; set;
898                 }
899
900                 public DocType Type {
901                         get; set;
902                 }
903         }
904
905         // #2155
906         public static int test_0_fullaot_sflda_cctor () {
907                 List<Doc> documents = new List<Doc>();
908                 documents.Add(new Doc { Name = "Doc1", Type = DocType.One } );
909                 documents.Add(new Doc { Name = "Doc2", Type = DocType.Two } );
910                 documents.Add(new Doc { Name = "Doc3", Type = DocType.Three } );
911                 documents.Add(new Doc { Name = "Doc4", Type = DocType.One } );
912                 documents.Add(new Doc { Name = "Doc5", Type = DocType.Two } );
913                 documents.Add(new Doc { Name = "Doc6", Type = DocType.Three } );
914                 documents.Add(new Doc { Name = "Doc7", Type = DocType.One } );
915                 documents.Add(new Doc { Name = "Doc8", Type = DocType.Two } );
916                 documents.Add(new Doc { Name = "Doc9", Type = DocType.Three } );
917
918                 List<DocType> categories = documents.Select(d=>d.Type).Distinct().ToList<DocType>().OrderBy(d => d).ToList();
919                 foreach(DocType cat in categories) {
920                         List<Doc> catDocs = documents.Where(d => d.Type == cat).OrderBy(d => d.Name).ToList<Doc>();
921                 }
922                 return 0;
923         }
924
925         class A { }
926
927     static List<A> sources = new List<A>();
928
929         // #6112
930     public static int test_0_fullaot_imt () {
931         sources.Add(null);
932         sources.Add(null);
933
934         int a = sources.Count;
935         var enumerator = sources.GetEnumerator() as IEnumerator<object>;
936
937         while (enumerator.MoveNext())
938         {
939             object o = enumerator.Current;
940         }
941
942                 return 0;
943         }
944 }