PageRenderTime 60ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/mono/mini/generics.cs

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