PageRenderTime 118ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 1ms

/IronPython_Main/Runtime/Tests/ETScenariosCSLinq/CSLinq/ExpressionCompiler/array_BackSl_index_BackSl_test0.cs

#
C# | 10651 lines | 9016 code | 1420 blank | 215 comment | 846 complexity | 58772e2b18712478e6f2280faba6af92 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. #if !CLR2
  2. using System.Linq.Expressions;
  3. #else
  4. using Microsoft.Scripting.Ast;
  5. using Microsoft.Scripting.Utils;
  6. #endif
  7. using System.Reflection;
  8. using System;
  9. namespace ExpressionCompiler {
  10. //-------- Scenario 3124
  11. namespace Scenario3124{
  12. public class Test
  13. {
  14. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "byte_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  15. public static Expression byte_ArrayIndex__() {
  16. if(Main() != 0 ) {
  17. throw new Exception();
  18. } else {
  19. return Expression.Constant(0);
  20. }
  21. }
  22. public static int Main()
  23. {
  24. Ext.StartCapture();
  25. bool success = false;
  26. try
  27. {
  28. success = check_byte_ArrayIndex();
  29. }
  30. finally
  31. {
  32. Ext.StopCapture();
  33. }
  34. return success ? 0 : 1;
  35. }
  36. static bool check_byte_ArrayIndex()
  37. {
  38. return checkEx_byte_ArrayIndex(null, -1) &
  39. checkEx_byte_ArrayIndex(null, 0) &
  40. checkEx_byte_ArrayIndex(null, 1) &
  41. check_byte_ArrayIndex(genArrbyte_ArrayIndex(0)) &
  42. check_byte_ArrayIndex(genArrbyte_ArrayIndex(1)) &
  43. check_byte_ArrayIndex(genArrbyte_ArrayIndex(5));
  44. }
  45. static byte[] genArrbyte_ArrayIndex(int size)
  46. {
  47. byte[] vals = new byte[] { 0, 1, byte.MaxValue };
  48. byte[] result = new byte[size];
  49. for (int i = 0; i < size; i++)
  50. {
  51. result[i] = vals[i % vals.Length];
  52. }
  53. return result;
  54. }
  55. static bool check_byte_ArrayIndex(byte[] val)
  56. {
  57. bool success = checkEx_byte_ArrayIndex(val, -1);
  58. for (int i = 0; i < val.Length; i++)
  59. {
  60. success &= check_byte_ArrayIndex(val, 0);
  61. }
  62. success &= checkEx_byte_ArrayIndex(val, val.Length);
  63. return success;
  64. }
  65. static bool checkEx_byte_ArrayIndex(byte[] val, int index)
  66. {
  67. try
  68. {
  69. check_byte_ArrayIndex(val, index);
  70. Console.WriteLine("byte_ArrayIndex[" + index + "] failed");
  71. return false;
  72. }
  73. catch
  74. {
  75. return true;
  76. }
  77. }
  78. static bool check_byte_ArrayIndex(byte[] val, int index)
  79. {
  80. Expression<Func<byte>> e =
  81. Expression.Lambda<Func<byte>>(
  82. Expression.ArrayIndex(Expression.Constant(val, typeof(byte[])),
  83. Expression.Constant(index, typeof(int))),
  84. new System.Collections.Generic.List<ParameterExpression>());
  85. Func<byte> f = e.Compile();
  86. return object.Equals(f(), val[index]);
  87. }
  88. }
  89. public static class Ext {
  90. public static void StartCapture() {
  91. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  92. // m.Invoke(null, new object[] { "test.dll" });
  93. }
  94. public static void StopCapture() {
  95. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  96. // m.Invoke(null, new object[0]);
  97. }
  98. public static bool IsIntegralOrEnum(Type type) {
  99. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  100. case TypeCode.Byte:
  101. case TypeCode.SByte:
  102. case TypeCode.Int16:
  103. case TypeCode.Int32:
  104. case TypeCode.Int64:
  105. case TypeCode.UInt16:
  106. case TypeCode.UInt32:
  107. case TypeCode.UInt64:
  108. return true;
  109. default:
  110. return false;
  111. }
  112. }
  113. public static bool IsFloating(Type type) {
  114. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  115. case TypeCode.Single:
  116. case TypeCode.Double:
  117. return true;
  118. default:
  119. return false;
  120. }
  121. }
  122. public static Type GetNonNullableType(Type type) {
  123. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  124. type.GetGenericArguments()[0] :
  125. type;
  126. }
  127. }
  128. }
  129. //-------- Scenario 3125
  130. namespace Scenario3125{
  131. public class Test
  132. {
  133. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "ushort_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  134. public static Expression ushort_ArrayIndex__() {
  135. if(Main() != 0 ) {
  136. throw new Exception();
  137. } else {
  138. return Expression.Constant(0);
  139. }
  140. }
  141. public static int Main()
  142. {
  143. Ext.StartCapture();
  144. bool success = false;
  145. try
  146. {
  147. success = check_ushort_ArrayIndex();
  148. }
  149. finally
  150. {
  151. Ext.StopCapture();
  152. }
  153. return success ? 0 : 1;
  154. }
  155. static bool check_ushort_ArrayIndex()
  156. {
  157. return checkEx_ushort_ArrayIndex(null, -1) &
  158. checkEx_ushort_ArrayIndex(null, 0) &
  159. checkEx_ushort_ArrayIndex(null, 1) &
  160. check_ushort_ArrayIndex(genArrushort_ArrayIndex(0)) &
  161. check_ushort_ArrayIndex(genArrushort_ArrayIndex(1)) &
  162. check_ushort_ArrayIndex(genArrushort_ArrayIndex(5));
  163. }
  164. static ushort[] genArrushort_ArrayIndex(int size)
  165. {
  166. ushort[] vals = new ushort[] { 0, 1, ushort.MaxValue };
  167. ushort[] result = new ushort[size];
  168. for (int i = 0; i < size; i++)
  169. {
  170. result[i] = vals[i % vals.Length];
  171. }
  172. return result;
  173. }
  174. static bool check_ushort_ArrayIndex(ushort[] val)
  175. {
  176. bool success = checkEx_ushort_ArrayIndex(val, -1);
  177. for (int i = 0; i < val.Length; i++)
  178. {
  179. success &= check_ushort_ArrayIndex(val, 0);
  180. }
  181. success &= checkEx_ushort_ArrayIndex(val, val.Length);
  182. return success;
  183. }
  184. static bool checkEx_ushort_ArrayIndex(ushort[] val, int index)
  185. {
  186. try
  187. {
  188. check_ushort_ArrayIndex(val, index);
  189. Console.WriteLine("ushort_ArrayIndex[" + index + "] failed");
  190. return false;
  191. }
  192. catch
  193. {
  194. return true;
  195. }
  196. }
  197. static bool check_ushort_ArrayIndex(ushort[] val, int index)
  198. {
  199. Expression<Func<ushort>> e =
  200. Expression.Lambda<Func<ushort>>(
  201. Expression.ArrayIndex(Expression.Constant(val, typeof(ushort[])),
  202. Expression.Constant(index, typeof(int))),
  203. new System.Collections.Generic.List<ParameterExpression>());
  204. Func<ushort> f = e.Compile();
  205. return object.Equals(f(), val[index]);
  206. }
  207. }
  208. public static class Ext {
  209. public static void StartCapture() {
  210. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  211. // m.Invoke(null, new object[] { "test.dll" });
  212. }
  213. public static void StopCapture() {
  214. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  215. // m.Invoke(null, new object[0]);
  216. }
  217. public static bool IsIntegralOrEnum(Type type) {
  218. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  219. case TypeCode.Byte:
  220. case TypeCode.SByte:
  221. case TypeCode.Int16:
  222. case TypeCode.Int32:
  223. case TypeCode.Int64:
  224. case TypeCode.UInt16:
  225. case TypeCode.UInt32:
  226. case TypeCode.UInt64:
  227. return true;
  228. default:
  229. return false;
  230. }
  231. }
  232. public static bool IsFloating(Type type) {
  233. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  234. case TypeCode.Single:
  235. case TypeCode.Double:
  236. return true;
  237. default:
  238. return false;
  239. }
  240. }
  241. public static Type GetNonNullableType(Type type) {
  242. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  243. type.GetGenericArguments()[0] :
  244. type;
  245. }
  246. }
  247. }
  248. //-------- Scenario 3126
  249. namespace Scenario3126{
  250. public class Test
  251. {
  252. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "uint_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  253. public static Expression uint_ArrayIndex__() {
  254. if(Main() != 0 ) {
  255. throw new Exception();
  256. } else {
  257. return Expression.Constant(0);
  258. }
  259. }
  260. public static int Main()
  261. {
  262. Ext.StartCapture();
  263. bool success = false;
  264. try
  265. {
  266. success = check_uint_ArrayIndex();
  267. }
  268. finally
  269. {
  270. Ext.StopCapture();
  271. }
  272. return success ? 0 : 1;
  273. }
  274. static bool check_uint_ArrayIndex()
  275. {
  276. return checkEx_uint_ArrayIndex(null, -1) &
  277. checkEx_uint_ArrayIndex(null, 0) &
  278. checkEx_uint_ArrayIndex(null, 1) &
  279. check_uint_ArrayIndex(genArruint_ArrayIndex(0)) &
  280. check_uint_ArrayIndex(genArruint_ArrayIndex(1)) &
  281. check_uint_ArrayIndex(genArruint_ArrayIndex(5));
  282. }
  283. static uint[] genArruint_ArrayIndex(int size)
  284. {
  285. uint[] vals = new uint[] { 0, 1, uint.MaxValue };
  286. uint[] result = new uint[size];
  287. for (int i = 0; i < size; i++)
  288. {
  289. result[i] = vals[i % vals.Length];
  290. }
  291. return result;
  292. }
  293. static bool check_uint_ArrayIndex(uint[] val)
  294. {
  295. bool success = checkEx_uint_ArrayIndex(val, -1);
  296. for (int i = 0; i < val.Length; i++)
  297. {
  298. success &= check_uint_ArrayIndex(val, 0);
  299. }
  300. success &= checkEx_uint_ArrayIndex(val, val.Length);
  301. return success;
  302. }
  303. static bool checkEx_uint_ArrayIndex(uint[] val, int index)
  304. {
  305. try
  306. {
  307. check_uint_ArrayIndex(val, index);
  308. Console.WriteLine("uint_ArrayIndex[" + index + "] failed");
  309. return false;
  310. }
  311. catch
  312. {
  313. return true;
  314. }
  315. }
  316. static bool check_uint_ArrayIndex(uint[] val, int index)
  317. {
  318. Expression<Func<uint>> e =
  319. Expression.Lambda<Func<uint>>(
  320. Expression.ArrayIndex(Expression.Constant(val, typeof(uint[])),
  321. Expression.Constant(index, typeof(int))),
  322. new System.Collections.Generic.List<ParameterExpression>());
  323. Func<uint> f = e.Compile();
  324. return object.Equals(f(), val[index]);
  325. }
  326. }
  327. public static class Ext {
  328. public static void StartCapture() {
  329. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  330. // m.Invoke(null, new object[] { "test.dll" });
  331. }
  332. public static void StopCapture() {
  333. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  334. // m.Invoke(null, new object[0]);
  335. }
  336. public static bool IsIntegralOrEnum(Type type) {
  337. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  338. case TypeCode.Byte:
  339. case TypeCode.SByte:
  340. case TypeCode.Int16:
  341. case TypeCode.Int32:
  342. case TypeCode.Int64:
  343. case TypeCode.UInt16:
  344. case TypeCode.UInt32:
  345. case TypeCode.UInt64:
  346. return true;
  347. default:
  348. return false;
  349. }
  350. }
  351. public static bool IsFloating(Type type) {
  352. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  353. case TypeCode.Single:
  354. case TypeCode.Double:
  355. return true;
  356. default:
  357. return false;
  358. }
  359. }
  360. public static Type GetNonNullableType(Type type) {
  361. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  362. type.GetGenericArguments()[0] :
  363. type;
  364. }
  365. }
  366. }
  367. //-------- Scenario 3127
  368. namespace Scenario3127{
  369. public class Test
  370. {
  371. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "ulong_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  372. public static Expression ulong_ArrayIndex__() {
  373. if(Main() != 0 ) {
  374. throw new Exception();
  375. } else {
  376. return Expression.Constant(0);
  377. }
  378. }
  379. public static int Main()
  380. {
  381. Ext.StartCapture();
  382. bool success = false;
  383. try
  384. {
  385. success = check_ulong_ArrayIndex();
  386. }
  387. finally
  388. {
  389. Ext.StopCapture();
  390. }
  391. return success ? 0 : 1;
  392. }
  393. static bool check_ulong_ArrayIndex()
  394. {
  395. return checkEx_ulong_ArrayIndex(null, -1) &
  396. checkEx_ulong_ArrayIndex(null, 0) &
  397. checkEx_ulong_ArrayIndex(null, 1) &
  398. check_ulong_ArrayIndex(genArrulong_ArrayIndex(0)) &
  399. check_ulong_ArrayIndex(genArrulong_ArrayIndex(1)) &
  400. check_ulong_ArrayIndex(genArrulong_ArrayIndex(5));
  401. }
  402. static ulong[] genArrulong_ArrayIndex(int size)
  403. {
  404. ulong[] vals = new ulong[] { 0, 1, ulong.MaxValue };
  405. ulong[] result = new ulong[size];
  406. for (int i = 0; i < size; i++)
  407. {
  408. result[i] = vals[i % vals.Length];
  409. }
  410. return result;
  411. }
  412. static bool check_ulong_ArrayIndex(ulong[] val)
  413. {
  414. bool success = checkEx_ulong_ArrayIndex(val, -1);
  415. for (int i = 0; i < val.Length; i++)
  416. {
  417. success &= check_ulong_ArrayIndex(val, 0);
  418. }
  419. success &= checkEx_ulong_ArrayIndex(val, val.Length);
  420. return success;
  421. }
  422. static bool checkEx_ulong_ArrayIndex(ulong[] val, int index)
  423. {
  424. try
  425. {
  426. check_ulong_ArrayIndex(val, index);
  427. Console.WriteLine("ulong_ArrayIndex[" + index + "] failed");
  428. return false;
  429. }
  430. catch
  431. {
  432. return true;
  433. }
  434. }
  435. static bool check_ulong_ArrayIndex(ulong[] val, int index)
  436. {
  437. Expression<Func<ulong>> e =
  438. Expression.Lambda<Func<ulong>>(
  439. Expression.ArrayIndex(Expression.Constant(val, typeof(ulong[])),
  440. Expression.Constant(index, typeof(int))),
  441. new System.Collections.Generic.List<ParameterExpression>());
  442. Func<ulong> f = e.Compile();
  443. return object.Equals(f(), val[index]);
  444. }
  445. }
  446. public static class Ext {
  447. public static void StartCapture() {
  448. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  449. // m.Invoke(null, new object[] { "test.dll" });
  450. }
  451. public static void StopCapture() {
  452. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  453. // m.Invoke(null, new object[0]);
  454. }
  455. public static bool IsIntegralOrEnum(Type type) {
  456. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  457. case TypeCode.Byte:
  458. case TypeCode.SByte:
  459. case TypeCode.Int16:
  460. case TypeCode.Int32:
  461. case TypeCode.Int64:
  462. case TypeCode.UInt16:
  463. case TypeCode.UInt32:
  464. case TypeCode.UInt64:
  465. return true;
  466. default:
  467. return false;
  468. }
  469. }
  470. public static bool IsFloating(Type type) {
  471. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  472. case TypeCode.Single:
  473. case TypeCode.Double:
  474. return true;
  475. default:
  476. return false;
  477. }
  478. }
  479. public static Type GetNonNullableType(Type type) {
  480. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  481. type.GetGenericArguments()[0] :
  482. type;
  483. }
  484. }
  485. }
  486. //-------- Scenario 3128
  487. namespace Scenario3128{
  488. public class Test
  489. {
  490. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "sbyte_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  491. public static Expression sbyte_ArrayIndex__() {
  492. if(Main() != 0 ) {
  493. throw new Exception();
  494. } else {
  495. return Expression.Constant(0);
  496. }
  497. }
  498. public static int Main()
  499. {
  500. Ext.StartCapture();
  501. bool success = false;
  502. try
  503. {
  504. success = check_sbyte_ArrayIndex();
  505. }
  506. finally
  507. {
  508. Ext.StopCapture();
  509. }
  510. return success ? 0 : 1;
  511. }
  512. static bool check_sbyte_ArrayIndex()
  513. {
  514. return checkEx_sbyte_ArrayIndex(null, -1) &
  515. checkEx_sbyte_ArrayIndex(null, 0) &
  516. checkEx_sbyte_ArrayIndex(null, 1) &
  517. check_sbyte_ArrayIndex(genArrsbyte_ArrayIndex(0)) &
  518. check_sbyte_ArrayIndex(genArrsbyte_ArrayIndex(1)) &
  519. check_sbyte_ArrayIndex(genArrsbyte_ArrayIndex(5));
  520. }
  521. static sbyte[] genArrsbyte_ArrayIndex(int size)
  522. {
  523. sbyte[] vals = new sbyte[] { 0, 1, -1, sbyte.MinValue, sbyte.MaxValue };
  524. sbyte[] result = new sbyte[size];
  525. for (int i = 0; i < size; i++)
  526. {
  527. result[i] = vals[i % vals.Length];
  528. }
  529. return result;
  530. }
  531. static bool check_sbyte_ArrayIndex(sbyte[] val)
  532. {
  533. bool success = checkEx_sbyte_ArrayIndex(val, -1);
  534. for (int i = 0; i < val.Length; i++)
  535. {
  536. success &= check_sbyte_ArrayIndex(val, 0);
  537. }
  538. success &= checkEx_sbyte_ArrayIndex(val, val.Length);
  539. return success;
  540. }
  541. static bool checkEx_sbyte_ArrayIndex(sbyte[] val, int index)
  542. {
  543. try
  544. {
  545. check_sbyte_ArrayIndex(val, index);
  546. Console.WriteLine("sbyte_ArrayIndex[" + index + "] failed");
  547. return false;
  548. }
  549. catch
  550. {
  551. return true;
  552. }
  553. }
  554. static bool check_sbyte_ArrayIndex(sbyte[] val, int index)
  555. {
  556. Expression<Func<sbyte>> e =
  557. Expression.Lambda<Func<sbyte>>(
  558. Expression.ArrayIndex(Expression.Constant(val, typeof(sbyte[])),
  559. Expression.Constant(index, typeof(int))),
  560. new System.Collections.Generic.List<ParameterExpression>());
  561. Func<sbyte> f = e.Compile();
  562. return object.Equals(f(), val[index]);
  563. }
  564. }
  565. public static class Ext {
  566. public static void StartCapture() {
  567. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  568. // m.Invoke(null, new object[] { "test.dll" });
  569. }
  570. public static void StopCapture() {
  571. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  572. // m.Invoke(null, new object[0]);
  573. }
  574. public static bool IsIntegralOrEnum(Type type) {
  575. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  576. case TypeCode.Byte:
  577. case TypeCode.SByte:
  578. case TypeCode.Int16:
  579. case TypeCode.Int32:
  580. case TypeCode.Int64:
  581. case TypeCode.UInt16:
  582. case TypeCode.UInt32:
  583. case TypeCode.UInt64:
  584. return true;
  585. default:
  586. return false;
  587. }
  588. }
  589. public static bool IsFloating(Type type) {
  590. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  591. case TypeCode.Single:
  592. case TypeCode.Double:
  593. return true;
  594. default:
  595. return false;
  596. }
  597. }
  598. public static Type GetNonNullableType(Type type) {
  599. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  600. type.GetGenericArguments()[0] :
  601. type;
  602. }
  603. }
  604. }
  605. //-------- Scenario 3129
  606. namespace Scenario3129{
  607. public class Test
  608. {
  609. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "short_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  610. public static Expression short_ArrayIndex__() {
  611. if(Main() != 0 ) {
  612. throw new Exception();
  613. } else {
  614. return Expression.Constant(0);
  615. }
  616. }
  617. public static int Main()
  618. {
  619. Ext.StartCapture();
  620. bool success = false;
  621. try
  622. {
  623. success = check_short_ArrayIndex();
  624. }
  625. finally
  626. {
  627. Ext.StopCapture();
  628. }
  629. return success ? 0 : 1;
  630. }
  631. static bool check_short_ArrayIndex()
  632. {
  633. return checkEx_short_ArrayIndex(null, -1) &
  634. checkEx_short_ArrayIndex(null, 0) &
  635. checkEx_short_ArrayIndex(null, 1) &
  636. check_short_ArrayIndex(genArrshort_ArrayIndex(0)) &
  637. check_short_ArrayIndex(genArrshort_ArrayIndex(1)) &
  638. check_short_ArrayIndex(genArrshort_ArrayIndex(5));
  639. }
  640. static short[] genArrshort_ArrayIndex(int size)
  641. {
  642. short[] vals = new short[] { 0, 1, -1, short.MinValue, short.MaxValue };
  643. short[] result = new short[size];
  644. for (int i = 0; i < size; i++)
  645. {
  646. result[i] = vals[i % vals.Length];
  647. }
  648. return result;
  649. }
  650. static bool check_short_ArrayIndex(short[] val)
  651. {
  652. bool success = checkEx_short_ArrayIndex(val, -1);
  653. for (int i = 0; i < val.Length; i++)
  654. {
  655. success &= check_short_ArrayIndex(val, 0);
  656. }
  657. success &= checkEx_short_ArrayIndex(val, val.Length);
  658. return success;
  659. }
  660. static bool checkEx_short_ArrayIndex(short[] val, int index)
  661. {
  662. try
  663. {
  664. check_short_ArrayIndex(val, index);
  665. Console.WriteLine("short_ArrayIndex[" + index + "] failed");
  666. return false;
  667. }
  668. catch
  669. {
  670. return true;
  671. }
  672. }
  673. static bool check_short_ArrayIndex(short[] val, int index)
  674. {
  675. Expression<Func<short>> e =
  676. Expression.Lambda<Func<short>>(
  677. Expression.ArrayIndex(Expression.Constant(val, typeof(short[])),
  678. Expression.Constant(index, typeof(int))),
  679. new System.Collections.Generic.List<ParameterExpression>());
  680. Func<short> f = e.Compile();
  681. return object.Equals(f(), val[index]);
  682. }
  683. }
  684. public static class Ext {
  685. public static void StartCapture() {
  686. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  687. // m.Invoke(null, new object[] { "test.dll" });
  688. }
  689. public static void StopCapture() {
  690. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  691. // m.Invoke(null, new object[0]);
  692. }
  693. public static bool IsIntegralOrEnum(Type type) {
  694. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  695. case TypeCode.Byte:
  696. case TypeCode.SByte:
  697. case TypeCode.Int16:
  698. case TypeCode.Int32:
  699. case TypeCode.Int64:
  700. case TypeCode.UInt16:
  701. case TypeCode.UInt32:
  702. case TypeCode.UInt64:
  703. return true;
  704. default:
  705. return false;
  706. }
  707. }
  708. public static bool IsFloating(Type type) {
  709. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  710. case TypeCode.Single:
  711. case TypeCode.Double:
  712. return true;
  713. default:
  714. return false;
  715. }
  716. }
  717. public static Type GetNonNullableType(Type type) {
  718. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  719. type.GetGenericArguments()[0] :
  720. type;
  721. }
  722. }
  723. }
  724. //-------- Scenario 3130
  725. namespace Scenario3130{
  726. public class Test
  727. {
  728. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "int_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  729. public static Expression int_ArrayIndex__() {
  730. if(Main() != 0 ) {
  731. throw new Exception();
  732. } else {
  733. return Expression.Constant(0);
  734. }
  735. }
  736. public static int Main()
  737. {
  738. Ext.StartCapture();
  739. bool success = false;
  740. try
  741. {
  742. success = check_int_ArrayIndex();
  743. }
  744. finally
  745. {
  746. Ext.StopCapture();
  747. }
  748. return success ? 0 : 1;
  749. }
  750. static bool check_int_ArrayIndex()
  751. {
  752. return checkEx_int_ArrayIndex(null, -1) &
  753. checkEx_int_ArrayIndex(null, 0) &
  754. checkEx_int_ArrayIndex(null, 1) &
  755. check_int_ArrayIndex(genArrint_ArrayIndex(0)) &
  756. check_int_ArrayIndex(genArrint_ArrayIndex(1)) &
  757. check_int_ArrayIndex(genArrint_ArrayIndex(5));
  758. }
  759. static int[] genArrint_ArrayIndex(int size)
  760. {
  761. int[] vals = new int[] { 0, 1, -1, int.MinValue, int.MaxValue };
  762. int[] result = new int[size];
  763. for (int i = 0; i < size; i++)
  764. {
  765. result[i] = vals[i % vals.Length];
  766. }
  767. return result;
  768. }
  769. static bool check_int_ArrayIndex(int[] val)
  770. {
  771. bool success = checkEx_int_ArrayIndex(val, -1);
  772. for (int i = 0; i < val.Length; i++)
  773. {
  774. success &= check_int_ArrayIndex(val, 0);
  775. }
  776. success &= checkEx_int_ArrayIndex(val, val.Length);
  777. return success;
  778. }
  779. static bool checkEx_int_ArrayIndex(int[] val, int index)
  780. {
  781. try
  782. {
  783. check_int_ArrayIndex(val, index);
  784. Console.WriteLine("int_ArrayIndex[" + index + "] failed");
  785. return false;
  786. }
  787. catch
  788. {
  789. return true;
  790. }
  791. }
  792. static bool check_int_ArrayIndex(int[] val, int index)
  793. {
  794. Expression<Func<int>> e =
  795. Expression.Lambda<Func<int>>(
  796. Expression.ArrayIndex(Expression.Constant(val, typeof(int[])),
  797. Expression.Constant(index, typeof(int))),
  798. new System.Collections.Generic.List<ParameterExpression>());
  799. Func<int> f = e.Compile();
  800. return object.Equals(f(), val[index]);
  801. }
  802. }
  803. public static class Ext {
  804. public static void StartCapture() {
  805. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  806. // m.Invoke(null, new object[] { "test.dll" });
  807. }
  808. public static void StopCapture() {
  809. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  810. // m.Invoke(null, new object[0]);
  811. }
  812. public static bool IsIntegralOrEnum(Type type) {
  813. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  814. case TypeCode.Byte:
  815. case TypeCode.SByte:
  816. case TypeCode.Int16:
  817. case TypeCode.Int32:
  818. case TypeCode.Int64:
  819. case TypeCode.UInt16:
  820. case TypeCode.UInt32:
  821. case TypeCode.UInt64:
  822. return true;
  823. default:
  824. return false;
  825. }
  826. }
  827. public static bool IsFloating(Type type) {
  828. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  829. case TypeCode.Single:
  830. case TypeCode.Double:
  831. return true;
  832. default:
  833. return false;
  834. }
  835. }
  836. public static Type GetNonNullableType(Type type) {
  837. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  838. type.GetGenericArguments()[0] :
  839. type;
  840. }
  841. }
  842. }
  843. //-------- Scenario 3131
  844. namespace Scenario3131{
  845. public class Test
  846. {
  847. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "long_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  848. public static Expression long_ArrayIndex__() {
  849. if(Main() != 0 ) {
  850. throw new Exception();
  851. } else {
  852. return Expression.Constant(0);
  853. }
  854. }
  855. public static int Main()
  856. {
  857. Ext.StartCapture();
  858. bool success = false;
  859. try
  860. {
  861. success = check_long_ArrayIndex();
  862. }
  863. finally
  864. {
  865. Ext.StopCapture();
  866. }
  867. return success ? 0 : 1;
  868. }
  869. static bool check_long_ArrayIndex()
  870. {
  871. return checkEx_long_ArrayIndex(null, -1) &
  872. checkEx_long_ArrayIndex(null, 0) &
  873. checkEx_long_ArrayIndex(null, 1) &
  874. check_long_ArrayIndex(genArrlong_ArrayIndex(0)) &
  875. check_long_ArrayIndex(genArrlong_ArrayIndex(1)) &
  876. check_long_ArrayIndex(genArrlong_ArrayIndex(5));
  877. }
  878. static long[] genArrlong_ArrayIndex(int size)
  879. {
  880. long[] vals = new long[] { 0, 1, -1, long.MinValue, long.MaxValue };
  881. long[] result = new long[size];
  882. for (int i = 0; i < size; i++)
  883. {
  884. result[i] = vals[i % vals.Length];
  885. }
  886. return result;
  887. }
  888. static bool check_long_ArrayIndex(long[] val)
  889. {
  890. bool success = checkEx_long_ArrayIndex(val, -1);
  891. for (int i = 0; i < val.Length; i++)
  892. {
  893. success &= check_long_ArrayIndex(val, 0);
  894. }
  895. success &= checkEx_long_ArrayIndex(val, val.Length);
  896. return success;
  897. }
  898. static bool checkEx_long_ArrayIndex(long[] val, int index)
  899. {
  900. try
  901. {
  902. check_long_ArrayIndex(val, index);
  903. Console.WriteLine("long_ArrayIndex[" + index + "] failed");
  904. return false;
  905. }
  906. catch
  907. {
  908. return true;
  909. }
  910. }
  911. static bool check_long_ArrayIndex(long[] val, int index)
  912. {
  913. Expression<Func<long>> e =
  914. Expression.Lambda<Func<long>>(
  915. Expression.ArrayIndex(Expression.Constant(val, typeof(long[])),
  916. Expression.Constant(index, typeof(int))),
  917. new System.Collections.Generic.List<ParameterExpression>());
  918. Func<long> f = e.Compile();
  919. return object.Equals(f(), val[index]);
  920. }
  921. }
  922. public static class Ext {
  923. public static void StartCapture() {
  924. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  925. // m.Invoke(null, new object[] { "test.dll" });
  926. }
  927. public static void StopCapture() {
  928. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  929. // m.Invoke(null, new object[0]);
  930. }
  931. public static bool IsIntegralOrEnum(Type type) {
  932. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  933. case TypeCode.Byte:
  934. case TypeCode.SByte:
  935. case TypeCode.Int16:
  936. case TypeCode.Int32:
  937. case TypeCode.Int64:
  938. case TypeCode.UInt16:
  939. case TypeCode.UInt32:
  940. case TypeCode.UInt64:
  941. return true;
  942. default:
  943. return false;
  944. }
  945. }
  946. public static bool IsFloating(Type type) {
  947. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  948. case TypeCode.Single:
  949. case TypeCode.Double:
  950. return true;
  951. default:
  952. return false;
  953. }
  954. }
  955. public static Type GetNonNullableType(Type type) {
  956. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  957. type.GetGenericArguments()[0] :
  958. type;
  959. }
  960. }
  961. }
  962. //-------- Scenario 3132
  963. namespace Scenario3132{
  964. public class Test
  965. {
  966. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "float_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  967. public static Expression float_ArrayIndex__() {
  968. if(Main() != 0 ) {
  969. throw new Exception();
  970. } else {
  971. return Expression.Constant(0);
  972. }
  973. }
  974. public static int Main()
  975. {
  976. Ext.StartCapture();
  977. bool success = false;
  978. try
  979. {
  980. success = check_float_ArrayIndex();
  981. }
  982. finally
  983. {
  984. Ext.StopCapture();
  985. }
  986. return success ? 0 : 1;
  987. }
  988. static bool check_float_ArrayIndex()
  989. {
  990. return checkEx_float_ArrayIndex(null, -1) &
  991. checkEx_float_ArrayIndex(null, 0) &
  992. checkEx_float_ArrayIndex(null, 1) &
  993. check_float_ArrayIndex(genArrfloat_ArrayIndex(0)) &
  994. check_float_ArrayIndex(genArrfloat_ArrayIndex(1)) &
  995. check_float_ArrayIndex(genArrfloat_ArrayIndex(5));
  996. }
  997. static float[] genArrfloat_ArrayIndex(int size)
  998. {
  999. float[] vals = new float[] { 0, 1, -1, float.MinValue, float.MaxValue, float.Epsilon, float.NegativeInfinity, float.PositiveInfinity, float.NaN };
  1000. float[] result = new float[size];
  1001. for (int i = 0; i < size; i++)
  1002. {
  1003. result[i] = vals[i % vals.Length];
  1004. }
  1005. return result;
  1006. }
  1007. static bool check_float_ArrayIndex(float[] val)
  1008. {
  1009. bool success = checkEx_float_ArrayIndex(val, -1);
  1010. for (int i = 0; i < val.Length; i++)
  1011. {
  1012. success &= check_float_ArrayIndex(val, 0);
  1013. }
  1014. success &= checkEx_float_ArrayIndex(val, val.Length);
  1015. return success;
  1016. }
  1017. static bool checkEx_float_ArrayIndex(float[] val, int index)
  1018. {
  1019. try
  1020. {
  1021. check_float_ArrayIndex(val, index);
  1022. Console.WriteLine("float_ArrayIndex[" + index + "] failed");
  1023. return false;
  1024. }
  1025. catch
  1026. {
  1027. return true;
  1028. }
  1029. }
  1030. static bool check_float_ArrayIndex(float[] val, int index)
  1031. {
  1032. Expression<Func<float>> e =
  1033. Expression.Lambda<Func<float>>(
  1034. Expression.ArrayIndex(Expression.Constant(val, typeof(float[])),
  1035. Expression.Constant(index, typeof(int))),
  1036. new System.Collections.Generic.List<ParameterExpression>());
  1037. Func<float> f = e.Compile();
  1038. return object.Equals(f(), val[index]);
  1039. }
  1040. }
  1041. public static class Ext {
  1042. public static void StartCapture() {
  1043. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1044. // m.Invoke(null, new object[] { "test.dll" });
  1045. }
  1046. public static void StopCapture() {
  1047. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1048. // m.Invoke(null, new object[0]);
  1049. }
  1050. public static bool IsIntegralOrEnum(Type type) {
  1051. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1052. case TypeCode.Byte:
  1053. case TypeCode.SByte:
  1054. case TypeCode.Int16:
  1055. case TypeCode.Int32:
  1056. case TypeCode.Int64:
  1057. case TypeCode.UInt16:
  1058. case TypeCode.UInt32:
  1059. case TypeCode.UInt64:
  1060. return true;
  1061. default:
  1062. return false;
  1063. }
  1064. }
  1065. public static bool IsFloating(Type type) {
  1066. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1067. case TypeCode.Single:
  1068. case TypeCode.Double:
  1069. return true;
  1070. default:
  1071. return false;
  1072. }
  1073. }
  1074. public static Type GetNonNullableType(Type type) {
  1075. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1076. type.GetGenericArguments()[0] :
  1077. type;
  1078. }
  1079. }
  1080. }
  1081. //-------- Scenario 3133
  1082. namespace Scenario3133{
  1083. public class Test
  1084. {
  1085. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "double_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1086. public static Expression double_ArrayIndex__() {
  1087. if(Main() != 0 ) {
  1088. throw new Exception();
  1089. } else {
  1090. return Expression.Constant(0);
  1091. }
  1092. }
  1093. public static int Main()
  1094. {
  1095. Ext.StartCapture();
  1096. bool success = false;
  1097. try
  1098. {
  1099. success = check_double_ArrayIndex();
  1100. }
  1101. finally
  1102. {
  1103. Ext.StopCapture();
  1104. }
  1105. return success ? 0 : 1;
  1106. }
  1107. static bool check_double_ArrayIndex()
  1108. {
  1109. return checkEx_double_ArrayIndex(null, -1) &
  1110. checkEx_double_ArrayIndex(null, 0) &
  1111. checkEx_double_ArrayIndex(null, 1) &
  1112. check_double_ArrayIndex(genArrdouble_ArrayIndex(0)) &
  1113. check_double_ArrayIndex(genArrdouble_ArrayIndex(1)) &
  1114. check_double_ArrayIndex(genArrdouble_ArrayIndex(5));
  1115. }
  1116. static double[] genArrdouble_ArrayIndex(int size)
  1117. {
  1118. double[] vals = new double[] { 0, 1, -1, double.MinValue, double.MaxValue, double.Epsilon, double.NegativeInfinity, double.PositiveInfinity, double.NaN };
  1119. double[] result = new double[size];
  1120. for (int i = 0; i < size; i++)
  1121. {
  1122. result[i] = vals[i % vals.Length];
  1123. }
  1124. return result;
  1125. }
  1126. static bool check_double_ArrayIndex(double[] val)
  1127. {
  1128. bool success = checkEx_double_ArrayIndex(val, -1);
  1129. for (int i = 0; i < val.Length; i++)
  1130. {
  1131. success &= check_double_ArrayIndex(val, 0);
  1132. }
  1133. success &= checkEx_double_ArrayIndex(val, val.Length);
  1134. return success;
  1135. }
  1136. static bool checkEx_double_ArrayIndex(double[] val, int index)
  1137. {
  1138. try
  1139. {
  1140. check_double_ArrayIndex(val, index);
  1141. Console.WriteLine("double_ArrayIndex[" + index + "] failed");
  1142. return false;
  1143. }
  1144. catch
  1145. {
  1146. return true;
  1147. }
  1148. }
  1149. static bool check_double_ArrayIndex(double[] val, int index)
  1150. {
  1151. Expression<Func<double>> e =
  1152. Expression.Lambda<Func<double>>(
  1153. Expression.ArrayIndex(Expression.Constant(val, typeof(double[])),
  1154. Expression.Constant(index, typeof(int))),
  1155. new System.Collections.Generic.List<ParameterExpression>());
  1156. Func<double> f = e.Compile();
  1157. return object.Equals(f(), val[index]);
  1158. }
  1159. }
  1160. public static class Ext {
  1161. public static void StartCapture() {
  1162. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1163. // m.Invoke(null, new object[] { "test.dll" });
  1164. }
  1165. public static void StopCapture() {
  1166. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1167. // m.Invoke(null, new object[0]);
  1168. }
  1169. public static bool IsIntegralOrEnum(Type type) {
  1170. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1171. case TypeCode.Byte:
  1172. case TypeCode.SByte:
  1173. case TypeCode.Int16:
  1174. case TypeCode.Int32:
  1175. case TypeCode.Int64:
  1176. case TypeCode.UInt16:
  1177. case TypeCode.UInt32:
  1178. case TypeCode.UInt64:
  1179. return true;
  1180. default:
  1181. return false;
  1182. }
  1183. }
  1184. public static bool IsFloating(Type type) {
  1185. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1186. case TypeCode.Single:
  1187. case TypeCode.Double:
  1188. return true;
  1189. default:
  1190. return false;
  1191. }
  1192. }
  1193. public static Type GetNonNullableType(Type type) {
  1194. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1195. type.GetGenericArguments()[0] :
  1196. type;
  1197. }
  1198. }
  1199. }
  1200. //-------- Scenario 3134
  1201. namespace Scenario3134{
  1202. public class Test
  1203. {
  1204. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "decimal_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1205. public static Expression decimal_ArrayIndex__() {
  1206. if(Main() != 0 ) {
  1207. throw new Exception();
  1208. } else {
  1209. return Expression.Constant(0);
  1210. }
  1211. }
  1212. public static int Main()
  1213. {
  1214. Ext.StartCapture();
  1215. bool success = false;
  1216. try
  1217. {
  1218. success = check_decimal_ArrayIndex();
  1219. }
  1220. finally
  1221. {
  1222. Ext.StopCapture();
  1223. }
  1224. return success ? 0 : 1;
  1225. }
  1226. static bool check_decimal_ArrayIndex()
  1227. {
  1228. return checkEx_decimal_ArrayIndex(null, -1) &
  1229. checkEx_decimal_ArrayIndex(null, 0) &
  1230. checkEx_decimal_ArrayIndex(null, 1) &
  1231. check_decimal_ArrayIndex(genArrdecimal_ArrayIndex(0)) &
  1232. check_decimal_ArrayIndex(genArrdecimal_ArrayIndex(1)) &
  1233. check_decimal_ArrayIndex(genArrdecimal_ArrayIndex(5));
  1234. }
  1235. static decimal[] genArrdecimal_ArrayIndex(int size)
  1236. {
  1237. decimal[] vals = new decimal[] { decimal.Zero, decimal.One, decimal.MinusOne, decimal.MinValue, decimal.MaxValue };
  1238. decimal[] result = new decimal[size];
  1239. for (int i = 0; i < size; i++)
  1240. {
  1241. result[i] = vals[i % vals.Length];
  1242. }
  1243. return result;
  1244. }
  1245. static bool check_decimal_ArrayIndex(decimal[] val)
  1246. {
  1247. bool success = checkEx_decimal_ArrayIndex(val, -1);
  1248. for (int i = 0; i < val.Length; i++)
  1249. {
  1250. success &= check_decimal_ArrayIndex(val, 0);
  1251. }
  1252. success &= checkEx_decimal_ArrayIndex(val, val.Length);
  1253. return success;
  1254. }
  1255. static bool checkEx_decimal_ArrayIndex(decimal[] val, int index)
  1256. {
  1257. try
  1258. {
  1259. check_decimal_ArrayIndex(val, index);
  1260. Console.WriteLine("decimal_ArrayIndex[" + index + "] failed");
  1261. return false;
  1262. }
  1263. catch
  1264. {
  1265. return true;
  1266. }
  1267. }
  1268. static bool check_decimal_ArrayIndex(decimal[] val, int index)
  1269. {
  1270. Expression<Func<decimal>> e =
  1271. Expression.Lambda<Func<decimal>>(
  1272. Expression.ArrayIndex(Expression.Constant(val, typeof(decimal[])),
  1273. Expression.Constant(index, typeof(int))),
  1274. new System.Collections.Generic.List<ParameterExpression>());
  1275. Func<decimal> f = e.Compile();
  1276. return object.Equals(f(), val[index]);
  1277. }
  1278. }
  1279. public static class Ext {
  1280. public static void StartCapture() {
  1281. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1282. // m.Invoke(null, new object[] { "test.dll" });
  1283. }
  1284. public static void StopCapture() {
  1285. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1286. // m.Invoke(null, new object[0]);
  1287. }
  1288. public static bool IsIntegralOrEnum(Type type) {
  1289. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1290. case TypeCode.Byte:
  1291. case TypeCode.SByte:
  1292. case TypeCode.Int16:
  1293. case TypeCode.Int32:
  1294. case TypeCode.Int64:
  1295. case TypeCode.UInt16:
  1296. case TypeCode.UInt32:
  1297. case TypeCode.UInt64:
  1298. return true;
  1299. default:
  1300. return false;
  1301. }
  1302. }
  1303. public static bool IsFloating(Type type) {
  1304. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1305. case TypeCode.Single:
  1306. case TypeCode.Double:
  1307. return true;
  1308. default:
  1309. return false;
  1310. }
  1311. }
  1312. public static Type GetNonNullableType(Type type) {
  1313. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1314. type.GetGenericArguments()[0] :
  1315. type;
  1316. }
  1317. }
  1318. }
  1319. //-------- Scenario 3135
  1320. namespace Scenario3135{
  1321. public class Test
  1322. {
  1323. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "char_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1324. public static Expression char_ArrayIndex__() {
  1325. if(Main() != 0 ) {
  1326. throw new Exception();
  1327. } else {
  1328. return Expression.Constant(0);
  1329. }
  1330. }
  1331. public static int Main()
  1332. {
  1333. Ext.StartCapture();
  1334. bool success = false;
  1335. try
  1336. {
  1337. success = check_char_ArrayIndex();
  1338. }
  1339. finally
  1340. {
  1341. Ext.StopCapture();
  1342. }
  1343. return success ? 0 : 1;
  1344. }
  1345. static bool check_char_ArrayIndex()
  1346. {
  1347. return checkEx_char_ArrayIndex(null, -1) &
  1348. checkEx_char_ArrayIndex(null, 0) &
  1349. checkEx_char_ArrayIndex(null, 1) &
  1350. check_char_ArrayIndex(genArrchar_ArrayIndex(0)) &
  1351. check_char_ArrayIndex(genArrchar_ArrayIndex(1)) &
  1352. check_char_ArrayIndex(genArrchar_ArrayIndex(5));
  1353. }
  1354. static char[] genArrchar_ArrayIndex(int size)
  1355. {
  1356. char[] vals = new char[] { '\0', '\b', 'A', '\uffff' };
  1357. char[] result = new char[size];
  1358. for (int i = 0; i < size; i++)
  1359. {
  1360. result[i] = vals[i % vals.Length];
  1361. }
  1362. return result;
  1363. }
  1364. static bool check_char_ArrayIndex(char[] val)
  1365. {
  1366. bool success = checkEx_char_ArrayIndex(val, -1);
  1367. for (int i = 0; i < val.Length; i++)
  1368. {
  1369. success &= check_char_ArrayIndex(val, 0);
  1370. }
  1371. success &= checkEx_char_ArrayIndex(val, val.Length);
  1372. return success;
  1373. }
  1374. static bool checkEx_char_ArrayIndex(char[] val, int index)
  1375. {
  1376. try
  1377. {
  1378. check_char_ArrayIndex(val, index);
  1379. Console.WriteLine("char_ArrayIndex[" + index + "] failed");
  1380. return false;
  1381. }
  1382. catch
  1383. {
  1384. return true;
  1385. }
  1386. }
  1387. static bool check_char_ArrayIndex(char[] val, int index)
  1388. {
  1389. Expression<Func<char>> e =
  1390. Expression.Lambda<Func<char>>(
  1391. Expression.ArrayIndex(Expression.Constant(val, typeof(char[])),
  1392. Expression.Constant(index, typeof(int))),
  1393. new System.Collections.Generic.List<ParameterExpression>());
  1394. Func<char> f = e.Compile();
  1395. return object.Equals(f(), val[index]);
  1396. }
  1397. }
  1398. public static class Ext {
  1399. public static void StartCapture() {
  1400. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1401. // m.Invoke(null, new object[] { "test.dll" });
  1402. }
  1403. public static void StopCapture() {
  1404. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1405. // m.Invoke(null, new object[0]);
  1406. }
  1407. public static bool IsIntegralOrEnum(Type type) {
  1408. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1409. case TypeCode.Byte:
  1410. case TypeCode.SByte:
  1411. case TypeCode.Int16:
  1412. case TypeCode.Int32:
  1413. case TypeCode.Int64:
  1414. case TypeCode.UInt16:
  1415. case TypeCode.UInt32:
  1416. case TypeCode.UInt64:
  1417. return true;
  1418. default:
  1419. return false;
  1420. }
  1421. }
  1422. public static bool IsFloating(Type type) {
  1423. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1424. case TypeCode.Single:
  1425. case TypeCode.Double:
  1426. return true;
  1427. default:
  1428. return false;
  1429. }
  1430. }
  1431. public static Type GetNonNullableType(Type type) {
  1432. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1433. type.GetGenericArguments()[0] :
  1434. type;
  1435. }
  1436. }
  1437. }
  1438. //-------- Scenario 3136
  1439. namespace Scenario3136{
  1440. public class Test
  1441. {
  1442. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "bool_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1443. public static Expression bool_ArrayIndex__() {
  1444. if(Main() != 0 ) {
  1445. throw new Exception();
  1446. } else {
  1447. return Expression.Constant(0);
  1448. }
  1449. }
  1450. public static int Main()
  1451. {
  1452. Ext.StartCapture();
  1453. bool success = false;
  1454. try
  1455. {
  1456. success = check_bool_ArrayIndex();
  1457. }
  1458. finally
  1459. {
  1460. Ext.StopCapture();
  1461. }
  1462. return success ? 0 : 1;
  1463. }
  1464. static bool check_bool_ArrayIndex()
  1465. {
  1466. return checkEx_bool_ArrayIndex(null, -1) &
  1467. checkEx_bool_ArrayIndex(null, 0) &
  1468. checkEx_bool_ArrayIndex(null, 1) &
  1469. check_bool_ArrayIndex(genArrbool_ArrayIndex(0)) &
  1470. check_bool_ArrayIndex(genArrbool_ArrayIndex(1)) &
  1471. check_bool_ArrayIndex(genArrbool_ArrayIndex(5));
  1472. }
  1473. static bool[] genArrbool_ArrayIndex(int size)
  1474. {
  1475. bool[] vals = new bool[] { true, false };
  1476. bool[] result = new bool[size];
  1477. for (int i = 0; i < size; i++)
  1478. {
  1479. result[i] = vals[i % vals.Length];
  1480. }
  1481. return result;
  1482. }
  1483. static bool check_bool_ArrayIndex(bool[] val)
  1484. {
  1485. bool success = checkEx_bool_ArrayIndex(val, -1);
  1486. for (int i = 0; i < val.Length; i++)
  1487. {
  1488. success &= check_bool_ArrayIndex(val, 0);
  1489. }
  1490. success &= checkEx_bool_ArrayIndex(val, val.Length);
  1491. return success;
  1492. }
  1493. static bool checkEx_bool_ArrayIndex(bool[] val, int index)
  1494. {
  1495. try
  1496. {
  1497. check_bool_ArrayIndex(val, index);
  1498. Console.WriteLine("bool_ArrayIndex[" + index + "] failed");
  1499. return false;
  1500. }
  1501. catch
  1502. {
  1503. return true;
  1504. }
  1505. }
  1506. static bool check_bool_ArrayIndex(bool[] val, int index)
  1507. {
  1508. Expression<Func<bool>> e =
  1509. Expression.Lambda<Func<bool>>(
  1510. Expression.ArrayIndex(Expression.Constant(val, typeof(bool[])),
  1511. Expression.Constant(index, typeof(int))),
  1512. new System.Collections.Generic.List<ParameterExpression>());
  1513. Func<bool> f = e.Compile();
  1514. return object.Equals(f(), val[index]);
  1515. }
  1516. }
  1517. public static class Ext {
  1518. public static void StartCapture() {
  1519. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1520. // m.Invoke(null, new object[] { "test.dll" });
  1521. }
  1522. public static void StopCapture() {
  1523. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1524. // m.Invoke(null, new object[0]);
  1525. }
  1526. public static bool IsIntegralOrEnum(Type type) {
  1527. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1528. case TypeCode.Byte:
  1529. case TypeCode.SByte:
  1530. case TypeCode.Int16:
  1531. case TypeCode.Int32:
  1532. case TypeCode.Int64:
  1533. case TypeCode.UInt16:
  1534. case TypeCode.UInt32:
  1535. case TypeCode.UInt64:
  1536. return true;
  1537. default:
  1538. return false;
  1539. }
  1540. }
  1541. public static bool IsFloating(Type type) {
  1542. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1543. case TypeCode.Single:
  1544. case TypeCode.Double:
  1545. return true;
  1546. default:
  1547. return false;
  1548. }
  1549. }
  1550. public static Type GetNonNullableType(Type type) {
  1551. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1552. type.GetGenericArguments()[0] :
  1553. type;
  1554. }
  1555. }
  1556. }
  1557. //-------- Scenario 3137
  1558. namespace Scenario3137{
  1559. public class Test
  1560. {
  1561. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "S_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1562. public static Expression S_ArrayIndex__() {
  1563. if(Main() != 0 ) {
  1564. throw new Exception();
  1565. } else {
  1566. return Expression.Constant(0);
  1567. }
  1568. }
  1569. public static int Main()
  1570. {
  1571. Ext.StartCapture();
  1572. bool success = false;
  1573. try
  1574. {
  1575. success = check_S_ArrayIndex();
  1576. }
  1577. finally
  1578. {
  1579. Ext.StopCapture();
  1580. }
  1581. return success ? 0 : 1;
  1582. }
  1583. static bool check_S_ArrayIndex()
  1584. {
  1585. return checkEx_S_ArrayIndex(null, -1) &
  1586. checkEx_S_ArrayIndex(null, 0) &
  1587. checkEx_S_ArrayIndex(null, 1) &
  1588. check_S_ArrayIndex(genArrS_ArrayIndex(0)) &
  1589. check_S_ArrayIndex(genArrS_ArrayIndex(1)) &
  1590. check_S_ArrayIndex(genArrS_ArrayIndex(5));
  1591. }
  1592. static S[] genArrS_ArrayIndex(int size)
  1593. {
  1594. S[] vals = new S[] { default(S), new S() };
  1595. S[] result = new S[size];
  1596. for (int i = 0; i < size; i++)
  1597. {
  1598. result[i] = vals[i % vals.Length];
  1599. }
  1600. return result;
  1601. }
  1602. static bool check_S_ArrayIndex(S[] val)
  1603. {
  1604. bool success = checkEx_S_ArrayIndex(val, -1);
  1605. for (int i = 0; i < val.Length; i++)
  1606. {
  1607. success &= check_S_ArrayIndex(val, 0);
  1608. }
  1609. success &= checkEx_S_ArrayIndex(val, val.Length);
  1610. return success;
  1611. }
  1612. static bool checkEx_S_ArrayIndex(S[] val, int index)
  1613. {
  1614. try
  1615. {
  1616. check_S_ArrayIndex(val, index);
  1617. Console.WriteLine("S_ArrayIndex[" + index + "] failed");
  1618. return false;
  1619. }
  1620. catch
  1621. {
  1622. return true;
  1623. }
  1624. }
  1625. static bool check_S_ArrayIndex(S[] val, int index)
  1626. {
  1627. Expression<Func<S>> e =
  1628. Expression.Lambda<Func<S>>(
  1629. Expression.ArrayIndex(Expression.Constant(val, typeof(S[])),
  1630. Expression.Constant(index, typeof(int))),
  1631. new System.Collections.Generic.List<ParameterExpression>());
  1632. Func<S> f = e.Compile();
  1633. return object.Equals(f(), val[index]);
  1634. }
  1635. }
  1636. public static class Ext {
  1637. public static void StartCapture() {
  1638. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1639. // m.Invoke(null, new object[] { "test.dll" });
  1640. }
  1641. public static void StopCapture() {
  1642. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1643. // m.Invoke(null, new object[0]);
  1644. }
  1645. public static bool IsIntegralOrEnum(Type type) {
  1646. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1647. case TypeCode.Byte:
  1648. case TypeCode.SByte:
  1649. case TypeCode.Int16:
  1650. case TypeCode.Int32:
  1651. case TypeCode.Int64:
  1652. case TypeCode.UInt16:
  1653. case TypeCode.UInt32:
  1654. case TypeCode.UInt64:
  1655. return true;
  1656. default:
  1657. return false;
  1658. }
  1659. }
  1660. public static bool IsFloating(Type type) {
  1661. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1662. case TypeCode.Single:
  1663. case TypeCode.Double:
  1664. return true;
  1665. default:
  1666. return false;
  1667. }
  1668. }
  1669. public static Type GetNonNullableType(Type type) {
  1670. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1671. type.GetGenericArguments()[0] :
  1672. type;
  1673. }
  1674. }
  1675. public interface I
  1676. {
  1677. void M();
  1678. }
  1679. public class C : IEquatable<C>, I
  1680. {
  1681. void I.M()
  1682. {
  1683. }
  1684. public override bool Equals(object o)
  1685. {
  1686. return o is C && Equals((C)o);
  1687. }
  1688. public bool Equals(C c)
  1689. {
  1690. return c != null;
  1691. }
  1692. public override int GetHashCode()
  1693. {
  1694. return 0;
  1695. }
  1696. }
  1697. public class D : C, IEquatable<D>
  1698. {
  1699. public int Val;
  1700. public D()
  1701. {
  1702. }
  1703. public D(int val)
  1704. {
  1705. Val = val;
  1706. }
  1707. public override bool Equals(object o)
  1708. {
  1709. return o is D && Equals((D)o);
  1710. }
  1711. public bool Equals(D d)
  1712. {
  1713. return d != null && d.Val == Val;
  1714. }
  1715. public override int GetHashCode()
  1716. {
  1717. return Val;
  1718. }
  1719. }
  1720. public enum E
  1721. {
  1722. A = 1, B = 2
  1723. }
  1724. public enum El : long
  1725. {
  1726. A, B, C
  1727. }
  1728. public struct S : IEquatable<S>
  1729. {
  1730. public override bool Equals(object o)
  1731. {
  1732. return (o is S) && Equals((S)o);
  1733. }
  1734. public bool Equals(S other)
  1735. {
  1736. return true;
  1737. }
  1738. public override int GetHashCode()
  1739. {
  1740. return 0;
  1741. }
  1742. }
  1743. public struct Sp : IEquatable<Sp>
  1744. {
  1745. public Sp(int i, double d)
  1746. {
  1747. I = i;
  1748. D = d;
  1749. }
  1750. public int I;
  1751. public double D;
  1752. public override bool Equals(object o)
  1753. {
  1754. return (o is Sp) && Equals((Sp)o);
  1755. }
  1756. public bool Equals(Sp other)
  1757. {
  1758. return other.I == I && other.D == D;
  1759. }
  1760. public override int GetHashCode()
  1761. {
  1762. return I.GetHashCode() ^ D.GetHashCode();
  1763. }
  1764. }
  1765. public struct Ss : IEquatable<Ss>
  1766. {
  1767. public Ss(S s)
  1768. {
  1769. Val = s;
  1770. }
  1771. public S Val;
  1772. public override bool Equals(object o)
  1773. {
  1774. return (o is Ss) && Equals((Ss)o);
  1775. }
  1776. public bool Equals(Ss other)
  1777. {
  1778. return other.Val.Equals(Val);
  1779. }
  1780. public override int GetHashCode()
  1781. {
  1782. return Val.GetHashCode();
  1783. }
  1784. }
  1785. public struct Sc : IEquatable<Sc>
  1786. {
  1787. public Sc(string s)
  1788. {
  1789. S = s;
  1790. }
  1791. public string S;
  1792. public override bool Equals(object o)
  1793. {
  1794. return (o is Sc) && Equals((Sc)o);
  1795. }
  1796. public bool Equals(Sc other)
  1797. {
  1798. return other.S == S;
  1799. }
  1800. public override int GetHashCode()
  1801. {
  1802. return S.GetHashCode();
  1803. }
  1804. }
  1805. public struct Scs : IEquatable<Scs>
  1806. {
  1807. public Scs(string s, S val)
  1808. {
  1809. S = s;
  1810. Val = val;
  1811. }
  1812. public string S;
  1813. public S Val;
  1814. public override bool Equals(object o)
  1815. {
  1816. return (o is Scs) && Equals((Scs)o);
  1817. }
  1818. public bool Equals(Scs other)
  1819. {
  1820. return other.S == S && other.Val.Equals(Val);
  1821. }
  1822. public override int GetHashCode()
  1823. {
  1824. return S.GetHashCode() ^ Val.GetHashCode();
  1825. }
  1826. }
  1827. }
  1828. //-------- Scenario 3138
  1829. namespace Scenario3138{
  1830. public class Test
  1831. {
  1832. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Sp_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1833. public static Expression Sp_ArrayIndex__() {
  1834. if(Main() != 0 ) {
  1835. throw new Exception();
  1836. } else {
  1837. return Expression.Constant(0);
  1838. }
  1839. }
  1840. public static int Main()
  1841. {
  1842. Ext.StartCapture();
  1843. bool success = false;
  1844. try
  1845. {
  1846. success = check_Sp_ArrayIndex();
  1847. }
  1848. finally
  1849. {
  1850. Ext.StopCapture();
  1851. }
  1852. return success ? 0 : 1;
  1853. }
  1854. static bool check_Sp_ArrayIndex()
  1855. {
  1856. return checkEx_Sp_ArrayIndex(null, -1) &
  1857. checkEx_Sp_ArrayIndex(null, 0) &
  1858. checkEx_Sp_ArrayIndex(null, 1) &
  1859. check_Sp_ArrayIndex(genArrSp_ArrayIndex(0)) &
  1860. check_Sp_ArrayIndex(genArrSp_ArrayIndex(1)) &
  1861. check_Sp_ArrayIndex(genArrSp_ArrayIndex(5));
  1862. }
  1863. static Sp[] genArrSp_ArrayIndex(int size)
  1864. {
  1865. Sp[] vals = new Sp[] { default(Sp), new Sp(), new Sp(5, 5.0) };
  1866. Sp[] result = new Sp[size];
  1867. for (int i = 0; i < size; i++)
  1868. {
  1869. result[i] = vals[i % vals.Length];
  1870. }
  1871. return result;
  1872. }
  1873. static bool check_Sp_ArrayIndex(Sp[] val)
  1874. {
  1875. bool success = checkEx_Sp_ArrayIndex(val, -1);
  1876. for (int i = 0; i < val.Length; i++)
  1877. {
  1878. success &= check_Sp_ArrayIndex(val, 0);
  1879. }
  1880. success &= checkEx_Sp_ArrayIndex(val, val.Length);
  1881. return success;
  1882. }
  1883. static bool checkEx_Sp_ArrayIndex(Sp[] val, int index)
  1884. {
  1885. try
  1886. {
  1887. check_Sp_ArrayIndex(val, index);
  1888. Console.WriteLine("Sp_ArrayIndex[" + index + "] failed");
  1889. return false;
  1890. }
  1891. catch
  1892. {
  1893. return true;
  1894. }
  1895. }
  1896. static bool check_Sp_ArrayIndex(Sp[] val, int index)
  1897. {
  1898. Expression<Func<Sp>> e =
  1899. Expression.Lambda<Func<Sp>>(
  1900. Expression.ArrayIndex(Expression.Constant(val, typeof(Sp[])),
  1901. Expression.Constant(index, typeof(int))),
  1902. new System.Collections.Generic.List<ParameterExpression>());
  1903. Func<Sp> f = e.Compile();
  1904. return object.Equals(f(), val[index]);
  1905. }
  1906. }
  1907. public static class Ext {
  1908. public static void StartCapture() {
  1909. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1910. // m.Invoke(null, new object[] { "test.dll" });
  1911. }
  1912. public static void StopCapture() {
  1913. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1914. // m.Invoke(null, new object[0]);
  1915. }
  1916. public static bool IsIntegralOrEnum(Type type) {
  1917. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1918. case TypeCode.Byte:
  1919. case TypeCode.SByte:
  1920. case TypeCode.Int16:
  1921. case TypeCode.Int32:
  1922. case TypeCode.Int64:
  1923. case TypeCode.UInt16:
  1924. case TypeCode.UInt32:
  1925. case TypeCode.UInt64:
  1926. return true;
  1927. default:
  1928. return false;
  1929. }
  1930. }
  1931. public static bool IsFloating(Type type) {
  1932. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1933. case TypeCode.Single:
  1934. case TypeCode.Double:
  1935. return true;
  1936. default:
  1937. return false;
  1938. }
  1939. }
  1940. public static Type GetNonNullableType(Type type) {
  1941. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1942. type.GetGenericArguments()[0] :
  1943. type;
  1944. }
  1945. }
  1946. public interface I
  1947. {
  1948. void M();
  1949. }
  1950. public class C : IEquatable<C>, I
  1951. {
  1952. void I.M()
  1953. {
  1954. }
  1955. public override bool Equals(object o)
  1956. {
  1957. return o is C && Equals((C)o);
  1958. }
  1959. public bool Equals(C c)
  1960. {
  1961. return c != null;
  1962. }
  1963. public override int GetHashCode()
  1964. {
  1965. return 0;
  1966. }
  1967. }
  1968. public class D : C, IEquatable<D>
  1969. {
  1970. public int Val;
  1971. public D()
  1972. {
  1973. }
  1974. public D(int val)
  1975. {
  1976. Val = val;
  1977. }
  1978. public override bool Equals(object o)
  1979. {
  1980. return o is D && Equals((D)o);
  1981. }
  1982. public bool Equals(D d)
  1983. {
  1984. return d != null && d.Val == Val;
  1985. }
  1986. public override int GetHashCode()
  1987. {
  1988. return Val;
  1989. }
  1990. }
  1991. public enum E
  1992. {
  1993. A = 1, B = 2
  1994. }
  1995. public enum El : long
  1996. {
  1997. A, B, C
  1998. }
  1999. public struct S : IEquatable<S>
  2000. {
  2001. public override bool Equals(object o)
  2002. {
  2003. return (o is S) && Equals((S)o);
  2004. }
  2005. public bool Equals(S other)
  2006. {
  2007. return true;
  2008. }
  2009. public override int GetHashCode()
  2010. {
  2011. return 0;
  2012. }
  2013. }
  2014. public struct Sp : IEquatable<Sp>
  2015. {
  2016. public Sp(int i, double d)
  2017. {
  2018. I = i;
  2019. D = d;
  2020. }
  2021. public int I;
  2022. public double D;
  2023. public override bool Equals(object o)
  2024. {
  2025. return (o is Sp) && Equals((Sp)o);
  2026. }
  2027. public bool Equals(Sp other)
  2028. {
  2029. return other.I == I && other.D == D;
  2030. }
  2031. public override int GetHashCode()
  2032. {
  2033. return I.GetHashCode() ^ D.GetHashCode();
  2034. }
  2035. }
  2036. public struct Ss : IEquatable<Ss>
  2037. {
  2038. public Ss(S s)
  2039. {
  2040. Val = s;
  2041. }
  2042. public S Val;
  2043. public override bool Equals(object o)
  2044. {
  2045. return (o is Ss) && Equals((Ss)o);
  2046. }
  2047. public bool Equals(Ss other)
  2048. {
  2049. return other.Val.Equals(Val);
  2050. }
  2051. public override int GetHashCode()
  2052. {
  2053. return Val.GetHashCode();
  2054. }
  2055. }
  2056. public struct Sc : IEquatable<Sc>
  2057. {
  2058. public Sc(string s)
  2059. {
  2060. S = s;
  2061. }
  2062. public string S;
  2063. public override bool Equals(object o)
  2064. {
  2065. return (o is Sc) && Equals((Sc)o);
  2066. }
  2067. public bool Equals(Sc other)
  2068. {
  2069. return other.S == S;
  2070. }
  2071. public override int GetHashCode()
  2072. {
  2073. return S.GetHashCode();
  2074. }
  2075. }
  2076. public struct Scs : IEquatable<Scs>
  2077. {
  2078. public Scs(string s, S val)
  2079. {
  2080. S = s;
  2081. Val = val;
  2082. }
  2083. public string S;
  2084. public S Val;
  2085. public override bool Equals(object o)
  2086. {
  2087. return (o is Scs) && Equals((Scs)o);
  2088. }
  2089. public bool Equals(Scs other)
  2090. {
  2091. return other.S == S && other.Val.Equals(Val);
  2092. }
  2093. public override int GetHashCode()
  2094. {
  2095. return S.GetHashCode() ^ Val.GetHashCode();
  2096. }
  2097. }
  2098. }
  2099. //-------- Scenario 3139
  2100. namespace Scenario3139{
  2101. public class Test
  2102. {
  2103. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Ss_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  2104. public static Expression Ss_ArrayIndex__() {
  2105. if(Main() != 0 ) {
  2106. throw new Exception();
  2107. } else {
  2108. return Expression.Constant(0);
  2109. }
  2110. }
  2111. public static int Main()
  2112. {
  2113. Ext.StartCapture();
  2114. bool success = false;
  2115. try
  2116. {
  2117. success = check_Ss_ArrayIndex();
  2118. }
  2119. finally
  2120. {
  2121. Ext.StopCapture();
  2122. }
  2123. return success ? 0 : 1;
  2124. }
  2125. static bool check_Ss_ArrayIndex()
  2126. {
  2127. return checkEx_Ss_ArrayIndex(null, -1) &
  2128. checkEx_Ss_ArrayIndex(null, 0) &
  2129. checkEx_Ss_ArrayIndex(null, 1) &
  2130. check_Ss_ArrayIndex(genArrSs_ArrayIndex(0)) &
  2131. check_Ss_ArrayIndex(genArrSs_ArrayIndex(1)) &
  2132. check_Ss_ArrayIndex(genArrSs_ArrayIndex(5));
  2133. }
  2134. static Ss[] genArrSs_ArrayIndex(int size)
  2135. {
  2136. Ss[] vals = new Ss[] { default(Ss), new Ss(), new Ss(new S()) };
  2137. Ss[] result = new Ss[size];
  2138. for (int i = 0; i < size; i++)
  2139. {
  2140. result[i] = vals[i % vals.Length];
  2141. }
  2142. return result;
  2143. }
  2144. static bool check_Ss_ArrayIndex(Ss[] val)
  2145. {
  2146. bool success = checkEx_Ss_ArrayIndex(val, -1);
  2147. for (int i = 0; i < val.Length; i++)
  2148. {
  2149. success &= check_Ss_ArrayIndex(val, 0);
  2150. }
  2151. success &= checkEx_Ss_ArrayIndex(val, val.Length);
  2152. return success;
  2153. }
  2154. static bool checkEx_Ss_ArrayIndex(Ss[] val, int index)
  2155. {
  2156. try
  2157. {
  2158. check_Ss_ArrayIndex(val, index);
  2159. Console.WriteLine("Ss_ArrayIndex[" + index + "] failed");
  2160. return false;
  2161. }
  2162. catch
  2163. {
  2164. return true;
  2165. }
  2166. }
  2167. static bool check_Ss_ArrayIndex(Ss[] val, int index)
  2168. {
  2169. Expression<Func<Ss>> e =
  2170. Expression.Lambda<Func<Ss>>(
  2171. Expression.ArrayIndex(Expression.Constant(val, typeof(Ss[])),
  2172. Expression.Constant(index, typeof(int))),
  2173. new System.Collections.Generic.List<ParameterExpression>());
  2174. Func<Ss> f = e.Compile();
  2175. return object.Equals(f(), val[index]);
  2176. }
  2177. }
  2178. public static class Ext {
  2179. public static void StartCapture() {
  2180. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2181. // m.Invoke(null, new object[] { "test.dll" });
  2182. }
  2183. public static void StopCapture() {
  2184. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2185. // m.Invoke(null, new object[0]);
  2186. }
  2187. public static bool IsIntegralOrEnum(Type type) {
  2188. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2189. case TypeCode.Byte:
  2190. case TypeCode.SByte:
  2191. case TypeCode.Int16:
  2192. case TypeCode.Int32:
  2193. case TypeCode.Int64:
  2194. case TypeCode.UInt16:
  2195. case TypeCode.UInt32:
  2196. case TypeCode.UInt64:
  2197. return true;
  2198. default:
  2199. return false;
  2200. }
  2201. }
  2202. public static bool IsFloating(Type type) {
  2203. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2204. case TypeCode.Single:
  2205. case TypeCode.Double:
  2206. return true;
  2207. default:
  2208. return false;
  2209. }
  2210. }
  2211. public static Type GetNonNullableType(Type type) {
  2212. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  2213. type.GetGenericArguments()[0] :
  2214. type;
  2215. }
  2216. }
  2217. public interface I
  2218. {
  2219. void M();
  2220. }
  2221. public class C : IEquatable<C>, I
  2222. {
  2223. void I.M()
  2224. {
  2225. }
  2226. public override bool Equals(object o)
  2227. {
  2228. return o is C && Equals((C)o);
  2229. }
  2230. public bool Equals(C c)
  2231. {
  2232. return c != null;
  2233. }
  2234. public override int GetHashCode()
  2235. {
  2236. return 0;
  2237. }
  2238. }
  2239. public class D : C, IEquatable<D>
  2240. {
  2241. public int Val;
  2242. public D()
  2243. {
  2244. }
  2245. public D(int val)
  2246. {
  2247. Val = val;
  2248. }
  2249. public override bool Equals(object o)
  2250. {
  2251. return o is D && Equals((D)o);
  2252. }
  2253. public bool Equals(D d)
  2254. {
  2255. return d != null && d.Val == Val;
  2256. }
  2257. public override int GetHashCode()
  2258. {
  2259. return Val;
  2260. }
  2261. }
  2262. public enum E
  2263. {
  2264. A = 1, B = 2
  2265. }
  2266. public enum El : long
  2267. {
  2268. A, B, C
  2269. }
  2270. public struct S : IEquatable<S>
  2271. {
  2272. public override bool Equals(object o)
  2273. {
  2274. return (o is S) && Equals((S)o);
  2275. }
  2276. public bool Equals(S other)
  2277. {
  2278. return true;
  2279. }
  2280. public override int GetHashCode()
  2281. {
  2282. return 0;
  2283. }
  2284. }
  2285. public struct Sp : IEquatable<Sp>
  2286. {
  2287. public Sp(int i, double d)
  2288. {
  2289. I = i;
  2290. D = d;
  2291. }
  2292. public int I;
  2293. public double D;
  2294. public override bool Equals(object o)
  2295. {
  2296. return (o is Sp) && Equals((Sp)o);
  2297. }
  2298. public bool Equals(Sp other)
  2299. {
  2300. return other.I == I && other.D == D;
  2301. }
  2302. public override int GetHashCode()
  2303. {
  2304. return I.GetHashCode() ^ D.GetHashCode();
  2305. }
  2306. }
  2307. public struct Ss : IEquatable<Ss>
  2308. {
  2309. public Ss(S s)
  2310. {
  2311. Val = s;
  2312. }
  2313. public S Val;
  2314. public override bool Equals(object o)
  2315. {
  2316. return (o is Ss) && Equals((Ss)o);
  2317. }
  2318. public bool Equals(Ss other)
  2319. {
  2320. return other.Val.Equals(Val);
  2321. }
  2322. public override int GetHashCode()
  2323. {
  2324. return Val.GetHashCode();
  2325. }
  2326. }
  2327. public struct Sc : IEquatable<Sc>
  2328. {
  2329. public Sc(string s)
  2330. {
  2331. S = s;
  2332. }
  2333. public string S;
  2334. public override bool Equals(object o)
  2335. {
  2336. return (o is Sc) && Equals((Sc)o);
  2337. }
  2338. public bool Equals(Sc other)
  2339. {
  2340. return other.S == S;
  2341. }
  2342. public override int GetHashCode()
  2343. {
  2344. return S.GetHashCode();
  2345. }
  2346. }
  2347. public struct Scs : IEquatable<Scs>
  2348. {
  2349. public Scs(string s, S val)
  2350. {
  2351. S = s;
  2352. Val = val;
  2353. }
  2354. public string S;
  2355. public S Val;
  2356. public override bool Equals(object o)
  2357. {
  2358. return (o is Scs) && Equals((Scs)o);
  2359. }
  2360. public bool Equals(Scs other)
  2361. {
  2362. return other.S == S && other.Val.Equals(Val);
  2363. }
  2364. public override int GetHashCode()
  2365. {
  2366. return S.GetHashCode() ^ Val.GetHashCode();
  2367. }
  2368. }
  2369. }
  2370. //-------- Scenario 3140
  2371. namespace Scenario3140{
  2372. public class Test
  2373. {
  2374. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Sc_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  2375. public static Expression Sc_ArrayIndex__() {
  2376. if(Main() != 0 ) {
  2377. throw new Exception();
  2378. } else {
  2379. return Expression.Constant(0);
  2380. }
  2381. }
  2382. public static int Main()
  2383. {
  2384. Ext.StartCapture();
  2385. bool success = false;
  2386. try
  2387. {
  2388. success = check_Sc_ArrayIndex();
  2389. }
  2390. finally
  2391. {
  2392. Ext.StopCapture();
  2393. }
  2394. return success ? 0 : 1;
  2395. }
  2396. static bool check_Sc_ArrayIndex()
  2397. {
  2398. return checkEx_Sc_ArrayIndex(null, -1) &
  2399. checkEx_Sc_ArrayIndex(null, 0) &
  2400. checkEx_Sc_ArrayIndex(null, 1) &
  2401. check_Sc_ArrayIndex(genArrSc_ArrayIndex(0)) &
  2402. check_Sc_ArrayIndex(genArrSc_ArrayIndex(1)) &
  2403. check_Sc_ArrayIndex(genArrSc_ArrayIndex(5));
  2404. }
  2405. static Sc[] genArrSc_ArrayIndex(int size)
  2406. {
  2407. Sc[] vals = new Sc[] { default(Sc), new Sc(), new Sc(null) };
  2408. Sc[] result = new Sc[size];
  2409. for (int i = 0; i < size; i++)
  2410. {
  2411. result[i] = vals[i % vals.Length];
  2412. }
  2413. return result;
  2414. }
  2415. static bool check_Sc_ArrayIndex(Sc[] val)
  2416. {
  2417. bool success = checkEx_Sc_ArrayIndex(val, -1);
  2418. for (int i = 0; i < val.Length; i++)
  2419. {
  2420. success &= check_Sc_ArrayIndex(val, 0);
  2421. }
  2422. success &= checkEx_Sc_ArrayIndex(val, val.Length);
  2423. return success;
  2424. }
  2425. static bool checkEx_Sc_ArrayIndex(Sc[] val, int index)
  2426. {
  2427. try
  2428. {
  2429. check_Sc_ArrayIndex(val, index);
  2430. Console.WriteLine("Sc_ArrayIndex[" + index + "] failed");
  2431. return false;
  2432. }
  2433. catch
  2434. {
  2435. return true;
  2436. }
  2437. }
  2438. static bool check_Sc_ArrayIndex(Sc[] val, int index)
  2439. {
  2440. Expression<Func<Sc>> e =
  2441. Expression.Lambda<Func<Sc>>(
  2442. Expression.ArrayIndex(Expression.Constant(val, typeof(Sc[])),
  2443. Expression.Constant(index, typeof(int))),
  2444. new System.Collections.Generic.List<ParameterExpression>());
  2445. Func<Sc> f = e.Compile();
  2446. return object.Equals(f(), val[index]);
  2447. }
  2448. }
  2449. public static class Ext {
  2450. public static void StartCapture() {
  2451. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2452. // m.Invoke(null, new object[] { "test.dll" });
  2453. }
  2454. public static void StopCapture() {
  2455. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2456. // m.Invoke(null, new object[0]);
  2457. }
  2458. public static bool IsIntegralOrEnum(Type type) {
  2459. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2460. case TypeCode.Byte:
  2461. case TypeCode.SByte:
  2462. case TypeCode.Int16:
  2463. case TypeCode.Int32:
  2464. case TypeCode.Int64:
  2465. case TypeCode.UInt16:
  2466. case TypeCode.UInt32:
  2467. case TypeCode.UInt64:
  2468. return true;
  2469. default:
  2470. return false;
  2471. }
  2472. }
  2473. public static bool IsFloating(Type type) {
  2474. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2475. case TypeCode.Single:
  2476. case TypeCode.Double:
  2477. return true;
  2478. default:
  2479. return false;
  2480. }
  2481. }
  2482. public static Type GetNonNullableType(Type type) {
  2483. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  2484. type.GetGenericArguments()[0] :
  2485. type;
  2486. }
  2487. }
  2488. public interface I
  2489. {
  2490. void M();
  2491. }
  2492. public class C : IEquatable<C>, I
  2493. {
  2494. void I.M()
  2495. {
  2496. }
  2497. public override bool Equals(object o)
  2498. {
  2499. return o is C && Equals((C)o);
  2500. }
  2501. public bool Equals(C c)
  2502. {
  2503. return c != null;
  2504. }
  2505. public override int GetHashCode()
  2506. {
  2507. return 0;
  2508. }
  2509. }
  2510. public class D : C, IEquatable<D>
  2511. {
  2512. public int Val;
  2513. public D()
  2514. {
  2515. }
  2516. public D(int val)
  2517. {
  2518. Val = val;
  2519. }
  2520. public override bool Equals(object o)
  2521. {
  2522. return o is D && Equals((D)o);
  2523. }
  2524. public bool Equals(D d)
  2525. {
  2526. return d != null && d.Val == Val;
  2527. }
  2528. public override int GetHashCode()
  2529. {
  2530. return Val;
  2531. }
  2532. }
  2533. public enum E
  2534. {
  2535. A = 1, B = 2
  2536. }
  2537. public enum El : long
  2538. {
  2539. A, B, C
  2540. }
  2541. public struct S : IEquatable<S>
  2542. {
  2543. public override bool Equals(object o)
  2544. {
  2545. return (o is S) && Equals((S)o);
  2546. }
  2547. public bool Equals(S other)
  2548. {
  2549. return true;
  2550. }
  2551. public override int GetHashCode()
  2552. {
  2553. return 0;
  2554. }
  2555. }
  2556. public struct Sp : IEquatable<Sp>
  2557. {
  2558. public Sp(int i, double d)
  2559. {
  2560. I = i;
  2561. D = d;
  2562. }
  2563. public int I;
  2564. public double D;
  2565. public override bool Equals(object o)
  2566. {
  2567. return (o is Sp) && Equals((Sp)o);
  2568. }
  2569. public bool Equals(Sp other)
  2570. {
  2571. return other.I == I && other.D == D;
  2572. }
  2573. public override int GetHashCode()
  2574. {
  2575. return I.GetHashCode() ^ D.GetHashCode();
  2576. }
  2577. }
  2578. public struct Ss : IEquatable<Ss>
  2579. {
  2580. public Ss(S s)
  2581. {
  2582. Val = s;
  2583. }
  2584. public S Val;
  2585. public override bool Equals(object o)
  2586. {
  2587. return (o is Ss) && Equals((Ss)o);
  2588. }
  2589. public bool Equals(Ss other)
  2590. {
  2591. return other.Val.Equals(Val);
  2592. }
  2593. public override int GetHashCode()
  2594. {
  2595. return Val.GetHashCode();
  2596. }
  2597. }
  2598. public struct Sc : IEquatable<Sc>
  2599. {
  2600. public Sc(string s)
  2601. {
  2602. S = s;
  2603. }
  2604. public string S;
  2605. public override bool Equals(object o)
  2606. {
  2607. return (o is Sc) && Equals((Sc)o);
  2608. }
  2609. public bool Equals(Sc other)
  2610. {
  2611. return other.S == S;
  2612. }
  2613. public override int GetHashCode()
  2614. {
  2615. return S.GetHashCode();
  2616. }
  2617. }
  2618. public struct Scs : IEquatable<Scs>
  2619. {
  2620. public Scs(string s, S val)
  2621. {
  2622. S = s;
  2623. Val = val;
  2624. }
  2625. public string S;
  2626. public S Val;
  2627. public override bool Equals(object o)
  2628. {
  2629. return (o is Scs) && Equals((Scs)o);
  2630. }
  2631. public bool Equals(Scs other)
  2632. {
  2633. return other.S == S && other.Val.Equals(Val);
  2634. }
  2635. public override int GetHashCode()
  2636. {
  2637. return S.GetHashCode() ^ Val.GetHashCode();
  2638. }
  2639. }
  2640. }
  2641. //-------- Scenario 3141
  2642. namespace Scenario3141{
  2643. public class Test
  2644. {
  2645. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Scs_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  2646. public static Expression Scs_ArrayIndex__() {
  2647. if(Main() != 0 ) {
  2648. throw new Exception();
  2649. } else {
  2650. return Expression.Constant(0);
  2651. }
  2652. }
  2653. public static int Main()
  2654. {
  2655. Ext.StartCapture();
  2656. bool success = false;
  2657. try
  2658. {
  2659. success = check_Scs_ArrayIndex();
  2660. }
  2661. finally
  2662. {
  2663. Ext.StopCapture();
  2664. }
  2665. return success ? 0 : 1;
  2666. }
  2667. static bool check_Scs_ArrayIndex()
  2668. {
  2669. return checkEx_Scs_ArrayIndex(null, -1) &
  2670. checkEx_Scs_ArrayIndex(null, 0) &
  2671. checkEx_Scs_ArrayIndex(null, 1) &
  2672. check_Scs_ArrayIndex(genArrScs_ArrayIndex(0)) &
  2673. check_Scs_ArrayIndex(genArrScs_ArrayIndex(1)) &
  2674. check_Scs_ArrayIndex(genArrScs_ArrayIndex(5));
  2675. }
  2676. static Scs[] genArrScs_ArrayIndex(int size)
  2677. {
  2678. Scs[] vals = new Scs[] { default(Scs), new Scs(), new Scs(null, new S()) };
  2679. Scs[] result = new Scs[size];
  2680. for (int i = 0; i < size; i++)
  2681. {
  2682. result[i] = vals[i % vals.Length];
  2683. }
  2684. return result;
  2685. }
  2686. static bool check_Scs_ArrayIndex(Scs[] val)
  2687. {
  2688. bool success = checkEx_Scs_ArrayIndex(val, -1);
  2689. for (int i = 0; i < val.Length; i++)
  2690. {
  2691. success &= check_Scs_ArrayIndex(val, 0);
  2692. }
  2693. success &= checkEx_Scs_ArrayIndex(val, val.Length);
  2694. return success;
  2695. }
  2696. static bool checkEx_Scs_ArrayIndex(Scs[] val, int index)
  2697. {
  2698. try
  2699. {
  2700. check_Scs_ArrayIndex(val, index);
  2701. Console.WriteLine("Scs_ArrayIndex[" + index + "] failed");
  2702. return false;
  2703. }
  2704. catch
  2705. {
  2706. return true;
  2707. }
  2708. }
  2709. static bool check_Scs_ArrayIndex(Scs[] val, int index)
  2710. {
  2711. Expression<Func<Scs>> e =
  2712. Expression.Lambda<Func<Scs>>(
  2713. Expression.ArrayIndex(Expression.Constant(val, typeof(Scs[])),
  2714. Expression.Constant(index, typeof(int))),
  2715. new System.Collections.Generic.List<ParameterExpression>());
  2716. Func<Scs> f = e.Compile();
  2717. return object.Equals(f(), val[index]);
  2718. }
  2719. }
  2720. public static class Ext {
  2721. public static void StartCapture() {
  2722. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2723. // m.Invoke(null, new object[] { "test.dll" });
  2724. }
  2725. public static void StopCapture() {
  2726. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2727. // m.Invoke(null, new object[0]);
  2728. }
  2729. public static bool IsIntegralOrEnum(Type type) {
  2730. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2731. case TypeCode.Byte:
  2732. case TypeCode.SByte:
  2733. case TypeCode.Int16:
  2734. case TypeCode.Int32:
  2735. case TypeCode.Int64:
  2736. case TypeCode.UInt16:
  2737. case TypeCode.UInt32:
  2738. case TypeCode.UInt64:
  2739. return true;
  2740. default:
  2741. return false;
  2742. }
  2743. }
  2744. public static bool IsFloating(Type type) {
  2745. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2746. case TypeCode.Single:
  2747. case TypeCode.Double:
  2748. return true;
  2749. default:
  2750. return false;
  2751. }
  2752. }
  2753. public static Type GetNonNullableType(Type type) {
  2754. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  2755. type.GetGenericArguments()[0] :
  2756. type;
  2757. }
  2758. }
  2759. public interface I
  2760. {
  2761. void M();
  2762. }
  2763. public class C : IEquatable<C>, I
  2764. {
  2765. void I.M()
  2766. {
  2767. }
  2768. public override bool Equals(object o)
  2769. {
  2770. return o is C && Equals((C)o);
  2771. }
  2772. public bool Equals(C c)
  2773. {
  2774. return c != null;
  2775. }
  2776. public override int GetHashCode()
  2777. {
  2778. return 0;
  2779. }
  2780. }
  2781. public class D : C, IEquatable<D>
  2782. {
  2783. public int Val;
  2784. public D()
  2785. {
  2786. }
  2787. public D(int val)
  2788. {
  2789. Val = val;
  2790. }
  2791. public override bool Equals(object o)
  2792. {
  2793. return o is D && Equals((D)o);
  2794. }
  2795. public bool Equals(D d)
  2796. {
  2797. return d != null && d.Val == Val;
  2798. }
  2799. public override int GetHashCode()
  2800. {
  2801. return Val;
  2802. }
  2803. }
  2804. public enum E
  2805. {
  2806. A = 1, B = 2
  2807. }
  2808. public enum El : long
  2809. {
  2810. A, B, C
  2811. }
  2812. public struct S : IEquatable<S>
  2813. {
  2814. public override bool Equals(object o)
  2815. {
  2816. return (o is S) && Equals((S)o);
  2817. }
  2818. public bool Equals(S other)
  2819. {
  2820. return true;
  2821. }
  2822. public override int GetHashCode()
  2823. {
  2824. return 0;
  2825. }
  2826. }
  2827. public struct Sp : IEquatable<Sp>
  2828. {
  2829. public Sp(int i, double d)
  2830. {
  2831. I = i;
  2832. D = d;
  2833. }
  2834. public int I;
  2835. public double D;
  2836. public override bool Equals(object o)
  2837. {
  2838. return (o is Sp) && Equals((Sp)o);
  2839. }
  2840. public bool Equals(Sp other)
  2841. {
  2842. return other.I == I && other.D == D;
  2843. }
  2844. public override int GetHashCode()
  2845. {
  2846. return I.GetHashCode() ^ D.GetHashCode();
  2847. }
  2848. }
  2849. public struct Ss : IEquatable<Ss>
  2850. {
  2851. public Ss(S s)
  2852. {
  2853. Val = s;
  2854. }
  2855. public S Val;
  2856. public override bool Equals(object o)
  2857. {
  2858. return (o is Ss) && Equals((Ss)o);
  2859. }
  2860. public bool Equals(Ss other)
  2861. {
  2862. return other.Val.Equals(Val);
  2863. }
  2864. public override int GetHashCode()
  2865. {
  2866. return Val.GetHashCode();
  2867. }
  2868. }
  2869. public struct Sc : IEquatable<Sc>
  2870. {
  2871. public Sc(string s)
  2872. {
  2873. S = s;
  2874. }
  2875. public string S;
  2876. public override bool Equals(object o)
  2877. {
  2878. return (o is Sc) && Equals((Sc)o);
  2879. }
  2880. public bool Equals(Sc other)
  2881. {
  2882. return other.S == S;
  2883. }
  2884. public override int GetHashCode()
  2885. {
  2886. return S.GetHashCode();
  2887. }
  2888. }
  2889. public struct Scs : IEquatable<Scs>
  2890. {
  2891. public Scs(string s, S val)
  2892. {
  2893. S = s;
  2894. Val = val;
  2895. }
  2896. public string S;
  2897. public S Val;
  2898. public override bool Equals(object o)
  2899. {
  2900. return (o is Scs) && Equals((Scs)o);
  2901. }
  2902. public bool Equals(Scs other)
  2903. {
  2904. return other.S == S && other.Val.Equals(Val);
  2905. }
  2906. public override int GetHashCode()
  2907. {
  2908. return S.GetHashCode() ^ Val.GetHashCode();
  2909. }
  2910. }
  2911. }
  2912. //-------- Scenario 3142
  2913. namespace Scenario3142{
  2914. public class Test
  2915. {
  2916. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Ts_ArrayIndex_S___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  2917. public static Expression Ts_ArrayIndex_S___() {
  2918. if(Main() != 0 ) {
  2919. throw new Exception();
  2920. } else {
  2921. return Expression.Constant(0);
  2922. }
  2923. }
  2924. public static int Main()
  2925. {
  2926. Ext.StartCapture();
  2927. bool success = false;
  2928. try
  2929. {
  2930. success = check_Ts_ArrayIndex<S>();
  2931. }
  2932. finally
  2933. {
  2934. Ext.StopCapture();
  2935. }
  2936. return success ? 0 : 1;
  2937. }
  2938. static bool check_Ts_ArrayIndex<Ts>() where Ts : struct
  2939. {
  2940. return checkEx_Ts_ArrayIndex<Ts>(null, -1) &
  2941. checkEx_Ts_ArrayIndex<Ts>(null, 0) &
  2942. checkEx_Ts_ArrayIndex<Ts>(null, 1) &
  2943. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(0)) &
  2944. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(1)) &
  2945. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(5));
  2946. }
  2947. static Ts[] genArrTs_ArrayIndex<Ts>(int size) where Ts : struct
  2948. {
  2949. Ts[] vals = new Ts[] { default(Ts), new Ts() };
  2950. Ts[] result = new Ts[size];
  2951. for (int i = 0; i < size; i++)
  2952. {
  2953. result[i] = vals[i % vals.Length];
  2954. }
  2955. return result;
  2956. }
  2957. static bool check_Ts_ArrayIndex<Ts>(Ts[] val) where Ts : struct
  2958. {
  2959. bool success = checkEx_Ts_ArrayIndex<Ts>(val, -1);
  2960. for (int i = 0; i < val.Length; i++)
  2961. {
  2962. success &= check_Ts_ArrayIndex<Ts>(val, 0);
  2963. }
  2964. success &= checkEx_Ts_ArrayIndex<Ts>(val, val.Length);
  2965. return success;
  2966. }
  2967. static bool checkEx_Ts_ArrayIndex<Ts>(Ts[] val, int index) where Ts : struct
  2968. {
  2969. try
  2970. {
  2971. check_Ts_ArrayIndex<Ts>(val, index);
  2972. Console.WriteLine("Ts_ArrayIndex[" + index + "] failed");
  2973. return false;
  2974. }
  2975. catch
  2976. {
  2977. return true;
  2978. }
  2979. }
  2980. static bool check_Ts_ArrayIndex<Ts>(Ts[] val, int index) where Ts : struct
  2981. {
  2982. Expression<Func<Ts>> e =
  2983. Expression.Lambda<Func<Ts>>(
  2984. Expression.ArrayIndex(Expression.Constant(val, typeof(Ts[])),
  2985. Expression.Constant(index, typeof(int))),
  2986. new System.Collections.Generic.List<ParameterExpression>());
  2987. Func<Ts> f = e.Compile();
  2988. return object.Equals(f(), val[index]);
  2989. }
  2990. }
  2991. public static class Ext {
  2992. public static void StartCapture() {
  2993. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2994. // m.Invoke(null, new object[] { "test.dll" });
  2995. }
  2996. public static void StopCapture() {
  2997. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2998. // m.Invoke(null, new object[0]);
  2999. }
  3000. public static bool IsIntegralOrEnum(Type type) {
  3001. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3002. case TypeCode.Byte:
  3003. case TypeCode.SByte:
  3004. case TypeCode.Int16:
  3005. case TypeCode.Int32:
  3006. case TypeCode.Int64:
  3007. case TypeCode.UInt16:
  3008. case TypeCode.UInt32:
  3009. case TypeCode.UInt64:
  3010. return true;
  3011. default:
  3012. return false;
  3013. }
  3014. }
  3015. public static bool IsFloating(Type type) {
  3016. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3017. case TypeCode.Single:
  3018. case TypeCode.Double:
  3019. return true;
  3020. default:
  3021. return false;
  3022. }
  3023. }
  3024. public static Type GetNonNullableType(Type type) {
  3025. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  3026. type.GetGenericArguments()[0] :
  3027. type;
  3028. }
  3029. }
  3030. public interface I
  3031. {
  3032. void M();
  3033. }
  3034. public class C : IEquatable<C>, I
  3035. {
  3036. void I.M()
  3037. {
  3038. }
  3039. public override bool Equals(object o)
  3040. {
  3041. return o is C && Equals((C)o);
  3042. }
  3043. public bool Equals(C c)
  3044. {
  3045. return c != null;
  3046. }
  3047. public override int GetHashCode()
  3048. {
  3049. return 0;
  3050. }
  3051. }
  3052. public class D : C, IEquatable<D>
  3053. {
  3054. public int Val;
  3055. public D()
  3056. {
  3057. }
  3058. public D(int val)
  3059. {
  3060. Val = val;
  3061. }
  3062. public override bool Equals(object o)
  3063. {
  3064. return o is D && Equals((D)o);
  3065. }
  3066. public bool Equals(D d)
  3067. {
  3068. return d != null && d.Val == Val;
  3069. }
  3070. public override int GetHashCode()
  3071. {
  3072. return Val;
  3073. }
  3074. }
  3075. public enum E
  3076. {
  3077. A = 1, B = 2
  3078. }
  3079. public enum El : long
  3080. {
  3081. A, B, C
  3082. }
  3083. public struct S : IEquatable<S>
  3084. {
  3085. public override bool Equals(object o)
  3086. {
  3087. return (o is S) && Equals((S)o);
  3088. }
  3089. public bool Equals(S other)
  3090. {
  3091. return true;
  3092. }
  3093. public override int GetHashCode()
  3094. {
  3095. return 0;
  3096. }
  3097. }
  3098. public struct Sp : IEquatable<Sp>
  3099. {
  3100. public Sp(int i, double d)
  3101. {
  3102. I = i;
  3103. D = d;
  3104. }
  3105. public int I;
  3106. public double D;
  3107. public override bool Equals(object o)
  3108. {
  3109. return (o is Sp) && Equals((Sp)o);
  3110. }
  3111. public bool Equals(Sp other)
  3112. {
  3113. return other.I == I && other.D == D;
  3114. }
  3115. public override int GetHashCode()
  3116. {
  3117. return I.GetHashCode() ^ D.GetHashCode();
  3118. }
  3119. }
  3120. public struct Ss : IEquatable<Ss>
  3121. {
  3122. public Ss(S s)
  3123. {
  3124. Val = s;
  3125. }
  3126. public S Val;
  3127. public override bool Equals(object o)
  3128. {
  3129. return (o is Ss) && Equals((Ss)o);
  3130. }
  3131. public bool Equals(Ss other)
  3132. {
  3133. return other.Val.Equals(Val);
  3134. }
  3135. public override int GetHashCode()
  3136. {
  3137. return Val.GetHashCode();
  3138. }
  3139. }
  3140. public struct Sc : IEquatable<Sc>
  3141. {
  3142. public Sc(string s)
  3143. {
  3144. S = s;
  3145. }
  3146. public string S;
  3147. public override bool Equals(object o)
  3148. {
  3149. return (o is Sc) && Equals((Sc)o);
  3150. }
  3151. public bool Equals(Sc other)
  3152. {
  3153. return other.S == S;
  3154. }
  3155. public override int GetHashCode()
  3156. {
  3157. return S.GetHashCode();
  3158. }
  3159. }
  3160. public struct Scs : IEquatable<Scs>
  3161. {
  3162. public Scs(string s, S val)
  3163. {
  3164. S = s;
  3165. Val = val;
  3166. }
  3167. public string S;
  3168. public S Val;
  3169. public override bool Equals(object o)
  3170. {
  3171. return (o is Scs) && Equals((Scs)o);
  3172. }
  3173. public bool Equals(Scs other)
  3174. {
  3175. return other.S == S && other.Val.Equals(Val);
  3176. }
  3177. public override int GetHashCode()
  3178. {
  3179. return S.GetHashCode() ^ Val.GetHashCode();
  3180. }
  3181. }
  3182. }
  3183. //-------- Scenario 3143
  3184. namespace Scenario3143{
  3185. public class Test
  3186. {
  3187. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Ts_ArrayIndex_Scs___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  3188. public static Expression Ts_ArrayIndex_Scs___() {
  3189. if(Main() != 0 ) {
  3190. throw new Exception();
  3191. } else {
  3192. return Expression.Constant(0);
  3193. }
  3194. }
  3195. public static int Main()
  3196. {
  3197. Ext.StartCapture();
  3198. bool success = false;
  3199. try
  3200. {
  3201. success = check_Ts_ArrayIndex<Scs>();
  3202. }
  3203. finally
  3204. {
  3205. Ext.StopCapture();
  3206. }
  3207. return success ? 0 : 1;
  3208. }
  3209. static bool check_Ts_ArrayIndex<Ts>() where Ts : struct
  3210. {
  3211. return checkEx_Ts_ArrayIndex<Ts>(null, -1) &
  3212. checkEx_Ts_ArrayIndex<Ts>(null, 0) &
  3213. checkEx_Ts_ArrayIndex<Ts>(null, 1) &
  3214. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(0)) &
  3215. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(1)) &
  3216. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(5));
  3217. }
  3218. static Ts[] genArrTs_ArrayIndex<Ts>(int size) where Ts : struct
  3219. {
  3220. Ts[] vals = new Ts[] { default(Ts), new Ts() };
  3221. Ts[] result = new Ts[size];
  3222. for (int i = 0; i < size; i++)
  3223. {
  3224. result[i] = vals[i % vals.Length];
  3225. }
  3226. return result;
  3227. }
  3228. static bool check_Ts_ArrayIndex<Ts>(Ts[] val) where Ts : struct
  3229. {
  3230. bool success = checkEx_Ts_ArrayIndex<Ts>(val, -1);
  3231. for (int i = 0; i < val.Length; i++)
  3232. {
  3233. success &= check_Ts_ArrayIndex<Ts>(val, 0);
  3234. }
  3235. success &= checkEx_Ts_ArrayIndex<Ts>(val, val.Length);
  3236. return success;
  3237. }
  3238. static bool checkEx_Ts_ArrayIndex<Ts>(Ts[] val, int index) where Ts : struct
  3239. {
  3240. try
  3241. {
  3242. check_Ts_ArrayIndex<Ts>(val, index);
  3243. Console.WriteLine("Ts_ArrayIndex[" + index + "] failed");
  3244. return false;
  3245. }
  3246. catch
  3247. {
  3248. return true;
  3249. }
  3250. }
  3251. static bool check_Ts_ArrayIndex<Ts>(Ts[] val, int index) where Ts : struct
  3252. {
  3253. Expression<Func<Ts>> e =
  3254. Expression.Lambda<Func<Ts>>(
  3255. Expression.ArrayIndex(Expression.Constant(val, typeof(Ts[])),
  3256. Expression.Constant(index, typeof(int))),
  3257. new System.Collections.Generic.List<ParameterExpression>());
  3258. Func<Ts> f = e.Compile();
  3259. return object.Equals(f(), val[index]);
  3260. }
  3261. }
  3262. public static class Ext {
  3263. public static void StartCapture() {
  3264. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3265. // m.Invoke(null, new object[] { "test.dll" });
  3266. }
  3267. public static void StopCapture() {
  3268. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3269. // m.Invoke(null, new object[0]);
  3270. }
  3271. public static bool IsIntegralOrEnum(Type type) {
  3272. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3273. case TypeCode.Byte:
  3274. case TypeCode.SByte:
  3275. case TypeCode.Int16:
  3276. case TypeCode.Int32:
  3277. case TypeCode.Int64:
  3278. case TypeCode.UInt16:
  3279. case TypeCode.UInt32:
  3280. case TypeCode.UInt64:
  3281. return true;
  3282. default:
  3283. return false;
  3284. }
  3285. }
  3286. public static bool IsFloating(Type type) {
  3287. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3288. case TypeCode.Single:
  3289. case TypeCode.Double:
  3290. return true;
  3291. default:
  3292. return false;
  3293. }
  3294. }
  3295. public static Type GetNonNullableType(Type type) {
  3296. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  3297. type.GetGenericArguments()[0] :
  3298. type;
  3299. }
  3300. }
  3301. public interface I
  3302. {
  3303. void M();
  3304. }
  3305. public class C : IEquatable<C>, I
  3306. {
  3307. void I.M()
  3308. {
  3309. }
  3310. public override bool Equals(object o)
  3311. {
  3312. return o is C && Equals((C)o);
  3313. }
  3314. public bool Equals(C c)
  3315. {
  3316. return c != null;
  3317. }
  3318. public override int GetHashCode()
  3319. {
  3320. return 0;
  3321. }
  3322. }
  3323. public class D : C, IEquatable<D>
  3324. {
  3325. public int Val;
  3326. public D()
  3327. {
  3328. }
  3329. public D(int val)
  3330. {
  3331. Val = val;
  3332. }
  3333. public override bool Equals(object o)
  3334. {
  3335. return o is D && Equals((D)o);
  3336. }
  3337. public bool Equals(D d)
  3338. {
  3339. return d != null && d.Val == Val;
  3340. }
  3341. public override int GetHashCode()
  3342. {
  3343. return Val;
  3344. }
  3345. }
  3346. public enum E
  3347. {
  3348. A = 1, B = 2
  3349. }
  3350. public enum El : long
  3351. {
  3352. A, B, C
  3353. }
  3354. public struct S : IEquatable<S>
  3355. {
  3356. public override bool Equals(object o)
  3357. {
  3358. return (o is S) && Equals((S)o);
  3359. }
  3360. public bool Equals(S other)
  3361. {
  3362. return true;
  3363. }
  3364. public override int GetHashCode()
  3365. {
  3366. return 0;
  3367. }
  3368. }
  3369. public struct Sp : IEquatable<Sp>
  3370. {
  3371. public Sp(int i, double d)
  3372. {
  3373. I = i;
  3374. D = d;
  3375. }
  3376. public int I;
  3377. public double D;
  3378. public override bool Equals(object o)
  3379. {
  3380. return (o is Sp) && Equals((Sp)o);
  3381. }
  3382. public bool Equals(Sp other)
  3383. {
  3384. return other.I == I && other.D == D;
  3385. }
  3386. public override int GetHashCode()
  3387. {
  3388. return I.GetHashCode() ^ D.GetHashCode();
  3389. }
  3390. }
  3391. public struct Ss : IEquatable<Ss>
  3392. {
  3393. public Ss(S s)
  3394. {
  3395. Val = s;
  3396. }
  3397. public S Val;
  3398. public override bool Equals(object o)
  3399. {
  3400. return (o is Ss) && Equals((Ss)o);
  3401. }
  3402. public bool Equals(Ss other)
  3403. {
  3404. return other.Val.Equals(Val);
  3405. }
  3406. public override int GetHashCode()
  3407. {
  3408. return Val.GetHashCode();
  3409. }
  3410. }
  3411. public struct Sc : IEquatable<Sc>
  3412. {
  3413. public Sc(string s)
  3414. {
  3415. S = s;
  3416. }
  3417. public string S;
  3418. public override bool Equals(object o)
  3419. {
  3420. return (o is Sc) && Equals((Sc)o);
  3421. }
  3422. public bool Equals(Sc other)
  3423. {
  3424. return other.S == S;
  3425. }
  3426. public override int GetHashCode()
  3427. {
  3428. return S.GetHashCode();
  3429. }
  3430. }
  3431. public struct Scs : IEquatable<Scs>
  3432. {
  3433. public Scs(string s, S val)
  3434. {
  3435. S = s;
  3436. Val = val;
  3437. }
  3438. public string S;
  3439. public S Val;
  3440. public override bool Equals(object o)
  3441. {
  3442. return (o is Scs) && Equals((Scs)o);
  3443. }
  3444. public bool Equals(Scs other)
  3445. {
  3446. return other.S == S && other.Val.Equals(Val);
  3447. }
  3448. public override int GetHashCode()
  3449. {
  3450. return S.GetHashCode() ^ Val.GetHashCode();
  3451. }
  3452. }
  3453. }
  3454. //-------- Scenario 3144
  3455. namespace Scenario3144{
  3456. public class Test
  3457. {
  3458. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Ts_ArrayIndex_E___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  3459. public static Expression Ts_ArrayIndex_E___() {
  3460. if(Main() != 0 ) {
  3461. throw new Exception();
  3462. } else {
  3463. return Expression.Constant(0);
  3464. }
  3465. }
  3466. public static int Main()
  3467. {
  3468. Ext.StartCapture();
  3469. bool success = false;
  3470. try
  3471. {
  3472. success = check_Ts_ArrayIndex<E>();
  3473. }
  3474. finally
  3475. {
  3476. Ext.StopCapture();
  3477. }
  3478. return success ? 0 : 1;
  3479. }
  3480. static bool check_Ts_ArrayIndex<Ts>() where Ts : struct
  3481. {
  3482. return checkEx_Ts_ArrayIndex<Ts>(null, -1) &
  3483. checkEx_Ts_ArrayIndex<Ts>(null, 0) &
  3484. checkEx_Ts_ArrayIndex<Ts>(null, 1) &
  3485. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(0)) &
  3486. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(1)) &
  3487. check_Ts_ArrayIndex<Ts>(genArrTs_ArrayIndex<Ts>(5));
  3488. }
  3489. static Ts[] genArrTs_ArrayIndex<Ts>(int size) where Ts : struct
  3490. {
  3491. Ts[] vals = new Ts[] { default(Ts), new Ts() };
  3492. Ts[] result = new Ts[size];
  3493. for (int i = 0; i < size; i++)
  3494. {
  3495. result[i] = vals[i % vals.Length];
  3496. }
  3497. return result;
  3498. }
  3499. static bool check_Ts_ArrayIndex<Ts>(Ts[] val) where Ts : struct
  3500. {
  3501. bool success = checkEx_Ts_ArrayIndex<Ts>(val, -1);
  3502. for (int i = 0; i < val.Length; i++)
  3503. {
  3504. success &= check_Ts_ArrayIndex<Ts>(val, 0);
  3505. }
  3506. success &= checkEx_Ts_ArrayIndex<Ts>(val, val.Length);
  3507. return success;
  3508. }
  3509. static bool checkEx_Ts_ArrayIndex<Ts>(Ts[] val, int index) where Ts : struct
  3510. {
  3511. try
  3512. {
  3513. check_Ts_ArrayIndex<Ts>(val, index);
  3514. Console.WriteLine("Ts_ArrayIndex[" + index + "] failed");
  3515. return false;
  3516. }
  3517. catch
  3518. {
  3519. return true;
  3520. }
  3521. }
  3522. static bool check_Ts_ArrayIndex<Ts>(Ts[] val, int index) where Ts : struct
  3523. {
  3524. Expression<Func<Ts>> e =
  3525. Expression.Lambda<Func<Ts>>(
  3526. Expression.ArrayIndex(Expression.Constant(val, typeof(Ts[])),
  3527. Expression.Constant(index, typeof(int))),
  3528. new System.Collections.Generic.List<ParameterExpression>());
  3529. Func<Ts> f = e.Compile();
  3530. return object.Equals(f(), val[index]);
  3531. }
  3532. }
  3533. public static class Ext {
  3534. public static void StartCapture() {
  3535. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3536. // m.Invoke(null, new object[] { "test.dll" });
  3537. }
  3538. public static void StopCapture() {
  3539. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3540. // m.Invoke(null, new object[0]);
  3541. }
  3542. public static bool IsIntegralOrEnum(Type type) {
  3543. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3544. case TypeCode.Byte:
  3545. case TypeCode.SByte:
  3546. case TypeCode.Int16:
  3547. case TypeCode.Int32:
  3548. case TypeCode.Int64:
  3549. case TypeCode.UInt16:
  3550. case TypeCode.UInt32:
  3551. case TypeCode.UInt64:
  3552. return true;
  3553. default:
  3554. return false;
  3555. }
  3556. }
  3557. public static bool IsFloating(Type type) {
  3558. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3559. case TypeCode.Single:
  3560. case TypeCode.Double:
  3561. return true;
  3562. default:
  3563. return false;
  3564. }
  3565. }
  3566. public static Type GetNonNullableType(Type type) {
  3567. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  3568. type.GetGenericArguments()[0] :
  3569. type;
  3570. }
  3571. }
  3572. public interface I
  3573. {
  3574. void M();
  3575. }
  3576. public class C : IEquatable<C>, I
  3577. {
  3578. void I.M()
  3579. {
  3580. }
  3581. public override bool Equals(object o)
  3582. {
  3583. return o is C && Equals((C)o);
  3584. }
  3585. public bool Equals(C c)
  3586. {
  3587. return c != null;
  3588. }
  3589. public override int GetHashCode()
  3590. {
  3591. return 0;
  3592. }
  3593. }
  3594. public class D : C, IEquatable<D>
  3595. {
  3596. public int Val;
  3597. public D()
  3598. {
  3599. }
  3600. public D(int val)
  3601. {
  3602. Val = val;
  3603. }
  3604. public override bool Equals(object o)
  3605. {
  3606. return o is D && Equals((D)o);
  3607. }
  3608. public bool Equals(D d)
  3609. {
  3610. return d != null && d.Val == Val;
  3611. }
  3612. public override int GetHashCode()
  3613. {
  3614. return Val;
  3615. }
  3616. }
  3617. public enum E
  3618. {
  3619. A = 1, B = 2
  3620. }
  3621. public enum El : long
  3622. {
  3623. A, B, C
  3624. }
  3625. public struct S : IEquatable<S>
  3626. {
  3627. public override bool Equals(object o)
  3628. {
  3629. return (o is S) && Equals((S)o);
  3630. }
  3631. public bool Equals(S other)
  3632. {
  3633. return true;
  3634. }
  3635. public override int GetHashCode()
  3636. {
  3637. return 0;
  3638. }
  3639. }
  3640. public struct Sp : IEquatable<Sp>
  3641. {
  3642. public Sp(int i, double d)
  3643. {
  3644. I = i;
  3645. D = d;
  3646. }
  3647. public int I;
  3648. public double D;
  3649. public override bool Equals(object o)
  3650. {
  3651. return (o is Sp) && Equals((Sp)o);
  3652. }
  3653. public bool Equals(Sp other)
  3654. {
  3655. return other.I == I && other.D == D;
  3656. }
  3657. public override int GetHashCode()
  3658. {
  3659. return I.GetHashCode() ^ D.GetHashCode();
  3660. }
  3661. }
  3662. public struct Ss : IEquatable<Ss>
  3663. {
  3664. public Ss(S s)
  3665. {
  3666. Val = s;
  3667. }
  3668. public S Val;
  3669. public override bool Equals(object o)
  3670. {
  3671. return (o is Ss) && Equals((Ss)o);
  3672. }
  3673. public bool Equals(Ss other)
  3674. {
  3675. return other.Val.Equals(Val);
  3676. }
  3677. public override int GetHashCode()
  3678. {
  3679. return Val.GetHashCode();
  3680. }
  3681. }
  3682. public struct Sc : IEquatable<Sc>
  3683. {
  3684. public Sc(string s)
  3685. {
  3686. S = s;
  3687. }
  3688. public string S;
  3689. public override bool Equals(object o)
  3690. {
  3691. return (o is Sc) && Equals((Sc)o);
  3692. }
  3693. public bool Equals(Sc other)
  3694. {
  3695. return other.S == S;
  3696. }
  3697. public override int GetHashCode()
  3698. {
  3699. return S.GetHashCode();
  3700. }
  3701. }
  3702. public struct Scs : IEquatable<Scs>
  3703. {
  3704. public Scs(string s, S val)
  3705. {
  3706. S = s;
  3707. Val = val;
  3708. }
  3709. public string S;
  3710. public S Val;
  3711. public override bool Equals(object o)
  3712. {
  3713. return (o is Scs) && Equals((Scs)o);
  3714. }
  3715. public bool Equals(Scs other)
  3716. {
  3717. return other.S == S && other.Val.Equals(Val);
  3718. }
  3719. public override int GetHashCode()
  3720. {
  3721. return S.GetHashCode() ^ Val.GetHashCode();
  3722. }
  3723. }
  3724. }
  3725. //-------- Scenario 3145
  3726. namespace Scenario3145{
  3727. public class Test
  3728. {
  3729. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "E_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  3730. public static Expression E_ArrayIndex__() {
  3731. if(Main() != 0 ) {
  3732. throw new Exception();
  3733. } else {
  3734. return Expression.Constant(0);
  3735. }
  3736. }
  3737. public static int Main()
  3738. {
  3739. Ext.StartCapture();
  3740. bool success = false;
  3741. try
  3742. {
  3743. success = check_E_ArrayIndex();
  3744. }
  3745. finally
  3746. {
  3747. Ext.StopCapture();
  3748. }
  3749. return success ? 0 : 1;
  3750. }
  3751. static bool check_E_ArrayIndex()
  3752. {
  3753. return checkEx_E_ArrayIndex(null, -1) &
  3754. checkEx_E_ArrayIndex(null, 0) &
  3755. checkEx_E_ArrayIndex(null, 1) &
  3756. check_E_ArrayIndex(genArrE_ArrayIndex(0)) &
  3757. check_E_ArrayIndex(genArrE_ArrayIndex(1)) &
  3758. check_E_ArrayIndex(genArrE_ArrayIndex(5));
  3759. }
  3760. static E[] genArrE_ArrayIndex(int size)
  3761. {
  3762. E[] vals = new E[] { (E)0, E.A, E.B, (E)int.MaxValue, (E)int.MinValue };
  3763. E[] result = new E[size];
  3764. for (int i = 0; i < size; i++)
  3765. {
  3766. result[i] = vals[i % vals.Length];
  3767. }
  3768. return result;
  3769. }
  3770. static bool check_E_ArrayIndex(E[] val)
  3771. {
  3772. bool success = checkEx_E_ArrayIndex(val, -1);
  3773. for (int i = 0; i < val.Length; i++)
  3774. {
  3775. success &= check_E_ArrayIndex(val, 0);
  3776. }
  3777. success &= checkEx_E_ArrayIndex(val, val.Length);
  3778. return success;
  3779. }
  3780. static bool checkEx_E_ArrayIndex(E[] val, int index)
  3781. {
  3782. try
  3783. {
  3784. check_E_ArrayIndex(val, index);
  3785. Console.WriteLine("E_ArrayIndex[" + index + "] failed");
  3786. return false;
  3787. }
  3788. catch
  3789. {
  3790. return true;
  3791. }
  3792. }
  3793. static bool check_E_ArrayIndex(E[] val, int index)
  3794. {
  3795. Expression<Func<E>> e =
  3796. Expression.Lambda<Func<E>>(
  3797. Expression.ArrayIndex(Expression.Constant(val, typeof(E[])),
  3798. Expression.Constant(index, typeof(int))),
  3799. new System.Collections.Generic.List<ParameterExpression>());
  3800. Func<E> f = e.Compile();
  3801. return object.Equals(f(), val[index]);
  3802. }
  3803. }
  3804. public static class Ext {
  3805. public static void StartCapture() {
  3806. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3807. // m.Invoke(null, new object[] { "test.dll" });
  3808. }
  3809. public static void StopCapture() {
  3810. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3811. // m.Invoke(null, new object[0]);
  3812. }
  3813. public static bool IsIntegralOrEnum(Type type) {
  3814. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3815. case TypeCode.Byte:
  3816. case TypeCode.SByte:
  3817. case TypeCode.Int16:
  3818. case TypeCode.Int32:
  3819. case TypeCode.Int64:
  3820. case TypeCode.UInt16:
  3821. case TypeCode.UInt32:
  3822. case TypeCode.UInt64:
  3823. return true;
  3824. default:
  3825. return false;
  3826. }
  3827. }
  3828. public static bool IsFloating(Type type) {
  3829. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3830. case TypeCode.Single:
  3831. case TypeCode.Double:
  3832. return true;
  3833. default:
  3834. return false;
  3835. }
  3836. }
  3837. public static Type GetNonNullableType(Type type) {
  3838. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  3839. type.GetGenericArguments()[0] :
  3840. type;
  3841. }
  3842. }
  3843. public interface I
  3844. {
  3845. void M();
  3846. }
  3847. public class C : IEquatable<C>, I
  3848. {
  3849. void I.M()
  3850. {
  3851. }
  3852. public override bool Equals(object o)
  3853. {
  3854. return o is C && Equals((C)o);
  3855. }
  3856. public bool Equals(C c)
  3857. {
  3858. return c != null;
  3859. }
  3860. public override int GetHashCode()
  3861. {
  3862. return 0;
  3863. }
  3864. }
  3865. public class D : C, IEquatable<D>
  3866. {
  3867. public int Val;
  3868. public D()
  3869. {
  3870. }
  3871. public D(int val)
  3872. {
  3873. Val = val;
  3874. }
  3875. public override bool Equals(object o)
  3876. {
  3877. return o is D && Equals((D)o);
  3878. }
  3879. public bool Equals(D d)
  3880. {
  3881. return d != null && d.Val == Val;
  3882. }
  3883. public override int GetHashCode()
  3884. {
  3885. return Val;
  3886. }
  3887. }
  3888. public enum E
  3889. {
  3890. A = 1, B = 2
  3891. }
  3892. public enum El : long
  3893. {
  3894. A, B, C
  3895. }
  3896. public struct S : IEquatable<S>
  3897. {
  3898. public override bool Equals(object o)
  3899. {
  3900. return (o is S) && Equals((S)o);
  3901. }
  3902. public bool Equals(S other)
  3903. {
  3904. return true;
  3905. }
  3906. public override int GetHashCode()
  3907. {
  3908. return 0;
  3909. }
  3910. }
  3911. public struct Sp : IEquatable<Sp>
  3912. {
  3913. public Sp(int i, double d)
  3914. {
  3915. I = i;
  3916. D = d;
  3917. }
  3918. public int I;
  3919. public double D;
  3920. public override bool Equals(object o)
  3921. {
  3922. return (o is Sp) && Equals((Sp)o);
  3923. }
  3924. public bool Equals(Sp other)
  3925. {
  3926. return other.I == I && other.D == D;
  3927. }
  3928. public override int GetHashCode()
  3929. {
  3930. return I.GetHashCode() ^ D.GetHashCode();
  3931. }
  3932. }
  3933. public struct Ss : IEquatable<Ss>
  3934. {
  3935. public Ss(S s)
  3936. {
  3937. Val = s;
  3938. }
  3939. public S Val;
  3940. public override bool Equals(object o)
  3941. {
  3942. return (o is Ss) && Equals((Ss)o);
  3943. }
  3944. public bool Equals(Ss other)
  3945. {
  3946. return other.Val.Equals(Val);
  3947. }
  3948. public override int GetHashCode()
  3949. {
  3950. return Val.GetHashCode();
  3951. }
  3952. }
  3953. public struct Sc : IEquatable<Sc>
  3954. {
  3955. public Sc(string s)
  3956. {
  3957. S = s;
  3958. }
  3959. public string S;
  3960. public override bool Equals(object o)
  3961. {
  3962. return (o is Sc) && Equals((Sc)o);
  3963. }
  3964. public bool Equals(Sc other)
  3965. {
  3966. return other.S == S;
  3967. }
  3968. public override int GetHashCode()
  3969. {
  3970. return S.GetHashCode();
  3971. }
  3972. }
  3973. public struct Scs : IEquatable<Scs>
  3974. {
  3975. public Scs(string s, S val)
  3976. {
  3977. S = s;
  3978. Val = val;
  3979. }
  3980. public string S;
  3981. public S Val;
  3982. public override bool Equals(object o)
  3983. {
  3984. return (o is Scs) && Equals((Scs)o);
  3985. }
  3986. public bool Equals(Scs other)
  3987. {
  3988. return other.S == S && other.Val.Equals(Val);
  3989. }
  3990. public override int GetHashCode()
  3991. {
  3992. return S.GetHashCode() ^ Val.GetHashCode();
  3993. }
  3994. }
  3995. }
  3996. //-------- Scenario 3146
  3997. namespace Scenario3146{
  3998. public class Test
  3999. {
  4000. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "El_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  4001. public static Expression El_ArrayIndex__() {
  4002. if(Main() != 0 ) {
  4003. throw new Exception();
  4004. } else {
  4005. return Expression.Constant(0);
  4006. }
  4007. }
  4008. public static int Main()
  4009. {
  4010. Ext.StartCapture();
  4011. bool success = false;
  4012. try
  4013. {
  4014. success = check_El_ArrayIndex();
  4015. }
  4016. finally
  4017. {
  4018. Ext.StopCapture();
  4019. }
  4020. return success ? 0 : 1;
  4021. }
  4022. static bool check_El_ArrayIndex()
  4023. {
  4024. return checkEx_El_ArrayIndex(null, -1) &
  4025. checkEx_El_ArrayIndex(null, 0) &
  4026. checkEx_El_ArrayIndex(null, 1) &
  4027. check_El_ArrayIndex(genArrEl_ArrayIndex(0)) &
  4028. check_El_ArrayIndex(genArrEl_ArrayIndex(1)) &
  4029. check_El_ArrayIndex(genArrEl_ArrayIndex(5));
  4030. }
  4031. static El[] genArrEl_ArrayIndex(int size)
  4032. {
  4033. El[] vals = new El[] { (El)0, El.A, El.B, (El)long.MaxValue, (El)long.MinValue };
  4034. El[] result = new El[size];
  4035. for (int i = 0; i < size; i++)
  4036. {
  4037. result[i] = vals[i % vals.Length];
  4038. }
  4039. return result;
  4040. }
  4041. static bool check_El_ArrayIndex(El[] val)
  4042. {
  4043. bool success = checkEx_El_ArrayIndex(val, -1);
  4044. for (int i = 0; i < val.Length; i++)
  4045. {
  4046. success &= check_El_ArrayIndex(val, 0);
  4047. }
  4048. success &= checkEx_El_ArrayIndex(val, val.Length);
  4049. return success;
  4050. }
  4051. static bool checkEx_El_ArrayIndex(El[] val, int index)
  4052. {
  4053. try
  4054. {
  4055. check_El_ArrayIndex(val, index);
  4056. Console.WriteLine("El_ArrayIndex[" + index + "] failed");
  4057. return false;
  4058. }
  4059. catch
  4060. {
  4061. return true;
  4062. }
  4063. }
  4064. static bool check_El_ArrayIndex(El[] val, int index)
  4065. {
  4066. Expression<Func<El>> e =
  4067. Expression.Lambda<Func<El>>(
  4068. Expression.ArrayIndex(Expression.Constant(val, typeof(El[])),
  4069. Expression.Constant(index, typeof(int))),
  4070. new System.Collections.Generic.List<ParameterExpression>());
  4071. Func<El> f = e.Compile();
  4072. return object.Equals(f(), val[index]);
  4073. }
  4074. }
  4075. public static class Ext {
  4076. public static void StartCapture() {
  4077. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  4078. // m.Invoke(null, new object[] { "test.dll" });
  4079. }
  4080. public static void StopCapture() {
  4081. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  4082. // m.Invoke(null, new object[0]);
  4083. }
  4084. public static bool IsIntegralOrEnum(Type type) {
  4085. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  4086. case TypeCode.Byte:
  4087. case TypeCode.SByte:
  4088. case TypeCode.Int16:
  4089. case TypeCode.Int32:
  4090. case TypeCode.Int64:
  4091. case TypeCode.UInt16:
  4092. case TypeCode.UInt32:
  4093. case TypeCode.UInt64:
  4094. return true;
  4095. default:
  4096. return false;
  4097. }
  4098. }
  4099. public static bool IsFloating(Type type) {
  4100. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  4101. case TypeCode.Single:
  4102. case TypeCode.Double:
  4103. return true;
  4104. default:
  4105. return false;
  4106. }
  4107. }
  4108. public static Type GetNonNullableType(Type type) {
  4109. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  4110. type.GetGenericArguments()[0] :
  4111. type;
  4112. }
  4113. }
  4114. public interface I
  4115. {
  4116. void M();
  4117. }
  4118. public class C : IEquatable<C>, I
  4119. {
  4120. void I.M()
  4121. {
  4122. }
  4123. public override bool Equals(object o)
  4124. {
  4125. return o is C && Equals((C)o);
  4126. }
  4127. public bool Equals(C c)
  4128. {
  4129. return c != null;
  4130. }
  4131. public override int GetHashCode()
  4132. {
  4133. return 0;
  4134. }
  4135. }
  4136. public class D : C, IEquatable<D>
  4137. {
  4138. public int Val;
  4139. public D()
  4140. {
  4141. }
  4142. public D(int val)
  4143. {
  4144. Val = val;
  4145. }
  4146. public override bool Equals(object o)
  4147. {
  4148. return o is D && Equals((D)o);
  4149. }
  4150. public bool Equals(D d)
  4151. {
  4152. return d != null && d.Val == Val;
  4153. }
  4154. public override int GetHashCode()
  4155. {
  4156. return Val;
  4157. }
  4158. }
  4159. public enum E
  4160. {
  4161. A = 1, B = 2
  4162. }
  4163. public enum El : long
  4164. {
  4165. A, B, C
  4166. }
  4167. public struct S : IEquatable<S>
  4168. {
  4169. public override bool Equals(object o)
  4170. {
  4171. return (o is S) && Equals((S)o);
  4172. }
  4173. public bool Equals(S other)
  4174. {
  4175. return true;
  4176. }
  4177. public override int GetHashCode()
  4178. {
  4179. return 0;
  4180. }
  4181. }
  4182. public struct Sp : IEquatable<Sp>
  4183. {
  4184. public Sp(int i, double d)
  4185. {
  4186. I = i;
  4187. D = d;
  4188. }
  4189. public int I;
  4190. public double D;
  4191. public override bool Equals(object o)
  4192. {
  4193. return (o is Sp) && Equals((Sp)o);
  4194. }
  4195. public bool Equals(Sp other)
  4196. {
  4197. return other.I == I && other.D == D;
  4198. }
  4199. public override int GetHashCode()
  4200. {
  4201. return I.GetHashCode() ^ D.GetHashCode();
  4202. }
  4203. }
  4204. public struct Ss : IEquatable<Ss>
  4205. {
  4206. public Ss(S s)
  4207. {
  4208. Val = s;
  4209. }
  4210. public S Val;
  4211. public override bool Equals(object o)
  4212. {
  4213. return (o is Ss) && Equals((Ss)o);
  4214. }
  4215. public bool Equals(Ss other)
  4216. {
  4217. return other.Val.Equals(Val);
  4218. }
  4219. public override int GetHashCode()
  4220. {
  4221. return Val.GetHashCode();
  4222. }
  4223. }
  4224. public struct Sc : IEquatable<Sc>
  4225. {
  4226. public Sc(string s)
  4227. {
  4228. S = s;
  4229. }
  4230. public string S;
  4231. public override bool Equals(object o)
  4232. {
  4233. return (o is Sc) && Equals((Sc)o);
  4234. }
  4235. public bool Equals(Sc other)
  4236. {
  4237. return other.S == S;
  4238. }
  4239. public override int GetHashCode()
  4240. {
  4241. return S.GetHashCode();
  4242. }
  4243. }
  4244. public struct Scs : IEquatable<Scs>
  4245. {
  4246. public Scs(string s, S val)
  4247. {
  4248. S = s;
  4249. Val = val;
  4250. }
  4251. public string S;
  4252. public S Val;
  4253. public override bool Equals(object o)
  4254. {
  4255. return (o is Scs) && Equals((Scs)o);
  4256. }
  4257. public bool Equals(Scs other)
  4258. {
  4259. return other.S == S && other.Val.Equals(Val);
  4260. }
  4261. public override int GetHashCode()
  4262. {
  4263. return S.GetHashCode() ^ Val.GetHashCode();
  4264. }
  4265. }
  4266. }
  4267. //-------- Scenario 3147
  4268. namespace Scenario3147{
  4269. public class Test
  4270. {
  4271. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "string_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  4272. public static Expression string_ArrayIndex__() {
  4273. if(Main() != 0 ) {
  4274. throw new Exception();
  4275. } else {
  4276. return Expression.Constant(0);
  4277. }
  4278. }
  4279. public static int Main()
  4280. {
  4281. Ext.StartCapture();
  4282. bool success = false;
  4283. try
  4284. {
  4285. success = check_string_ArrayIndex();
  4286. }
  4287. finally
  4288. {
  4289. Ext.StopCapture();
  4290. }
  4291. return success ? 0 : 1;
  4292. }
  4293. static bool check_string_ArrayIndex()
  4294. {
  4295. return checkEx_string_ArrayIndex(null, -1) &
  4296. checkEx_string_ArrayIndex(null, 0) &
  4297. checkEx_string_ArrayIndex(null, 1) &
  4298. check_string_ArrayIndex(genArrstring_ArrayIndex(0)) &
  4299. check_string_ArrayIndex(genArrstring_ArrayIndex(1)) &
  4300. check_string_ArrayIndex(genArrstring_ArrayIndex(5));
  4301. }
  4302. static string[] genArrstring_ArrayIndex(int size)
  4303. {
  4304. string[] vals = new string[] { null, "", "a", "foo" };
  4305. string[] result = new string[size];
  4306. for (int i = 0; i < size; i++)
  4307. {
  4308. result[i] = vals[i % vals.Length];
  4309. }
  4310. return result;
  4311. }
  4312. static bool check_string_ArrayIndex(string[] val)
  4313. {
  4314. bool success = checkEx_string_ArrayIndex(val, -1);
  4315. for (int i = 0; i < val.Length; i++)
  4316. {
  4317. success &= check_string_ArrayIndex(val, 0);
  4318. }
  4319. success &= checkEx_string_ArrayIndex(val, val.Length);
  4320. return success;
  4321. }
  4322. static bool checkEx_string_ArrayIndex(string[] val, int index)
  4323. {
  4324. try
  4325. {
  4326. check_string_ArrayIndex(val, index);
  4327. Console.WriteLine("string_ArrayIndex[" + index + "] failed");
  4328. return false;
  4329. }
  4330. catch
  4331. {
  4332. return true;
  4333. }
  4334. }
  4335. static bool check_string_ArrayIndex(string[] val, int index)
  4336. {
  4337. Expression<Func<string>> e =
  4338. Expression.Lambda<Func<string>>(
  4339. Expression.ArrayIndex(Expression.Constant(val, typeof(string[])),
  4340. Expression.Constant(index, typeof(int))),
  4341. new System.Collections.Generic.List<ParameterExpression>());
  4342. Func<string> f = e.Compile();
  4343. return object.Equals(f(), val[index]);
  4344. }
  4345. }
  4346. public static class Ext {
  4347. public static void StartCapture() {
  4348. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  4349. // m.Invoke(null, new object[] { "test.dll" });
  4350. }
  4351. public static void StopCapture() {
  4352. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  4353. // m.Invoke(null, new object[0]);
  4354. }
  4355. public static bool IsIntegralOrEnum(Type type) {
  4356. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  4357. case TypeCode.Byte:
  4358. case TypeCode.SByte:
  4359. case TypeCode.Int16:
  4360. case TypeCode.Int32:
  4361. case TypeCode.Int64:
  4362. case TypeCode.UInt16:
  4363. case TypeCode.UInt32:
  4364. case TypeCode.UInt64:
  4365. return true;
  4366. default:
  4367. return false;
  4368. }
  4369. }
  4370. public static bool IsFloating(Type type) {
  4371. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  4372. case TypeCode.Single:
  4373. case TypeCode.Double:
  4374. return true;
  4375. default:
  4376. return false;
  4377. }
  4378. }
  4379. public static Type GetNonNullableType(Type type) {
  4380. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  4381. type.GetGenericArguments()[0] :
  4382. type;
  4383. }
  4384. }
  4385. }
  4386. //-------- Scenario 3148
  4387. namespace Scenario3148{
  4388. public class Test
  4389. {
  4390. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "object_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  4391. public static Expression object_ArrayIndex__() {
  4392. if(Main() != 0 ) {
  4393. throw new Exception();
  4394. } else {
  4395. return Expression.Constant(0);
  4396. }
  4397. }
  4398. public static int Main()
  4399. {
  4400. Ext.StartCapture();
  4401. bool success = false;
  4402. try
  4403. {
  4404. success = check_object_ArrayIndex();
  4405. }
  4406. finally
  4407. {
  4408. Ext.StopCapture();
  4409. }
  4410. return success ? 0 : 1;
  4411. }
  4412. static bool check_object_ArrayIndex()
  4413. {
  4414. return checkEx_object_ArrayIndex(null, -1) &
  4415. checkEx_object_ArrayIndex(null, 0) &
  4416. checkEx_object_ArrayIndex(null, 1) &
  4417. check_object_ArrayIndex(genArrobject_ArrayIndex(0)) &
  4418. check_object_ArrayIndex(genArrobject_ArrayIndex(1)) &
  4419. check_object_ArrayIndex(genArrobject_ArrayIndex(5));
  4420. }
  4421. static object[] genArrobject_ArrayIndex(int size)
  4422. {
  4423. object[] vals = new object[] { null, new object(), new C(), new D(3) };
  4424. object[] result = new object[size];
  4425. for (int i = 0; i < size; i++)
  4426. {
  4427. result[i] = vals[i % vals.Length];
  4428. }
  4429. return result;
  4430. }
  4431. static bool check_object_ArrayIndex(object[] val)
  4432. {
  4433. bool success = checkEx_object_ArrayIndex(val, -1);
  4434. for (int i = 0; i < val.Length; i++)
  4435. {
  4436. success &= check_object_ArrayIndex(val, 0);
  4437. }
  4438. success &= checkEx_object_ArrayIndex(val, val.Length);
  4439. return success;
  4440. }
  4441. static bool checkEx_object_ArrayIndex(object[] val, int index)
  4442. {
  4443. try
  4444. {
  4445. check_object_ArrayIndex(val, index);
  4446. Console.WriteLine("object_ArrayIndex[" + index + "] failed");
  4447. return false;
  4448. }
  4449. catch
  4450. {
  4451. return true;
  4452. }
  4453. }
  4454. static bool check_object_ArrayIndex(object[] val, int index)
  4455. {
  4456. Expression<Func<object>> e =
  4457. Expression.Lambda<Func<object>>(
  4458. Expression.ArrayIndex(Expression.Constant(val, typeof(object[])),
  4459. Expression.Constant(index, typeof(int))),
  4460. new System.Collections.Generic.List<ParameterExpression>());
  4461. Func<object> f = e.Compile();
  4462. return object.Equals(f(), val[index]);
  4463. }
  4464. }
  4465. public static class Ext {
  4466. public static void StartCapture() {
  4467. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  4468. // m.Invoke(null, new object[] { "test.dll" });
  4469. }
  4470. public static void StopCapture() {
  4471. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  4472. // m.Invoke(null, new object[0]);
  4473. }
  4474. public static bool IsIntegralOrEnum(Type type) {
  4475. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  4476. case TypeCode.Byte:
  4477. case TypeCode.SByte:
  4478. case TypeCode.Int16:
  4479. case TypeCode.Int32:
  4480. case TypeCode.Int64:
  4481. case TypeCode.UInt16:
  4482. case TypeCode.UInt32:
  4483. case TypeCode.UInt64:
  4484. return true;
  4485. default:
  4486. return false;
  4487. }
  4488. }
  4489. public static bool IsFloating(Type type) {
  4490. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  4491. case TypeCode.Single:
  4492. case TypeCode.Double:
  4493. return true;
  4494. default:
  4495. return false;
  4496. }
  4497. }
  4498. public static Type GetNonNullableType(Type type) {
  4499. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  4500. type.GetGenericArguments()[0] :
  4501. type;
  4502. }
  4503. }
  4504. public interface I
  4505. {
  4506. void M();
  4507. }
  4508. public class C : IEquatable<C>, I
  4509. {
  4510. void I.M()
  4511. {
  4512. }
  4513. public override bool Equals(object o)
  4514. {
  4515. return o is C && Equals((C)o);
  4516. }
  4517. public bool Equals(C c)
  4518. {
  4519. return c != null;
  4520. }
  4521. public override int GetHashCode()
  4522. {
  4523. return 0;
  4524. }
  4525. }
  4526. public class D : C, IEquatable<D>
  4527. {
  4528. public int Val;
  4529. public D()
  4530. {
  4531. }
  4532. public D(int val)
  4533. {
  4534. Val = val;
  4535. }
  4536. public override bool Equals(object o)
  4537. {
  4538. return o is D && Equals((D)o);
  4539. }
  4540. public bool Equals(D d)
  4541. {
  4542. return d != null && d.Val == Val;
  4543. }
  4544. public override int GetHashCode()
  4545. {
  4546. return Val;
  4547. }
  4548. }
  4549. public enum E
  4550. {
  4551. A = 1, B = 2
  4552. }
  4553. public enum El : long
  4554. {
  4555. A, B, C
  4556. }
  4557. public struct S : IEquatable<S>
  4558. {
  4559. public override bool Equals(object o)
  4560. {
  4561. return (o is S) && Equals((S)o);
  4562. }
  4563. public bool Equals(S other)
  4564. {
  4565. return true;
  4566. }
  4567. public override int GetHashCode()
  4568. {
  4569. return 0;
  4570. }
  4571. }
  4572. public struct Sp : IEquatable<Sp>
  4573. {
  4574. public Sp(int i, double d)
  4575. {
  4576. I = i;
  4577. D = d;
  4578. }
  4579. public int I;
  4580. public double D;
  4581. public override bool Equals(object o)
  4582. {
  4583. return (o is Sp) && Equals((Sp)o);
  4584. }
  4585. public bool Equals(Sp other)
  4586. {
  4587. return other.I == I && other.D == D;
  4588. }
  4589. public override int GetHashCode()
  4590. {
  4591. return I.GetHashCode() ^ D.GetHashCode();
  4592. }
  4593. }
  4594. public struct Ss : IEquatable<Ss>
  4595. {
  4596. public Ss(S s)
  4597. {
  4598. Val = s;
  4599. }
  4600. public S Val;
  4601. public override bool Equals(object o)
  4602. {
  4603. return (o is Ss) && Equals((Ss)o);
  4604. }
  4605. public bool Equals(Ss other)
  4606. {
  4607. return other.Val.Equals(Val);
  4608. }
  4609. public override int GetHashCode()
  4610. {
  4611. return Val.GetHashCode();
  4612. }
  4613. }
  4614. public struct Sc : IEquatable<Sc>
  4615. {
  4616. public Sc(string s)
  4617. {
  4618. S = s;
  4619. }
  4620. public string S;
  4621. public override bool Equals(object o)
  4622. {
  4623. return (o is Sc) && Equals((Sc)o);
  4624. }
  4625. public bool Equals(Sc other)
  4626. {
  4627. return other.S == S;
  4628. }
  4629. public override int GetHashCode()
  4630. {
  4631. return S.GetHashCode();
  4632. }
  4633. }
  4634. public struct Scs : IEquatable<Scs>
  4635. {
  4636. public Scs(string s, S val)
  4637. {
  4638. S = s;
  4639. Val = val;
  4640. }
  4641. public string S;
  4642. public S Val;
  4643. public override bool Equals(object o)
  4644. {
  4645. return (o is Scs) && Equals((Scs)o);
  4646. }
  4647. public bool Equals(Scs other)
  4648. {
  4649. return other.S == S && other.Val.Equals(Val);
  4650. }
  4651. public override int GetHashCode()
  4652. {
  4653. return S.GetHashCode() ^ Val.GetHashCode();
  4654. }
  4655. }
  4656. }
  4657. //-------- Scenario 3149
  4658. namespace Scenario3149{
  4659. public class Test
  4660. {
  4661. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "C_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  4662. public static Expression C_ArrayIndex__() {
  4663. if(Main() != 0 ) {
  4664. throw new Exception();
  4665. } else {
  4666. return Expression.Constant(0);
  4667. }
  4668. }
  4669. public static int Main()
  4670. {
  4671. Ext.StartCapture();
  4672. bool success = false;
  4673. try
  4674. {
  4675. success = check_C_ArrayIndex();
  4676. }
  4677. finally
  4678. {
  4679. Ext.StopCapture();
  4680. }
  4681. return success ? 0 : 1;
  4682. }
  4683. static bool check_C_ArrayIndex()
  4684. {
  4685. return checkEx_C_ArrayIndex(null, -1) &
  4686. checkEx_C_ArrayIndex(null, 0) &
  4687. checkEx_C_ArrayIndex(null, 1) &
  4688. check_C_ArrayIndex(genArrC_ArrayIndex(0)) &
  4689. check_C_ArrayIndex(genArrC_ArrayIndex(1)) &
  4690. check_C_ArrayIndex(genArrC_ArrayIndex(5));
  4691. }
  4692. static C[] genArrC_ArrayIndex(int size)
  4693. {
  4694. C[] vals = new C[] { null, new C(), new D(), new D(0), new D(5) };
  4695. C[] result = new C[size];
  4696. for (int i = 0; i < size; i++)
  4697. {
  4698. result[i] = vals[i % vals.Length];
  4699. }
  4700. return result;
  4701. }
  4702. static bool check_C_ArrayIndex(C[] val)
  4703. {
  4704. bool success = checkEx_C_ArrayIndex(val, -1);
  4705. for (int i = 0; i < val.Length; i++)
  4706. {
  4707. success &= check_C_ArrayIndex(val, 0);
  4708. }
  4709. success &= checkEx_C_ArrayIndex(val, val.Length);
  4710. return success;
  4711. }
  4712. static bool checkEx_C_ArrayIndex(C[] val, int index)
  4713. {
  4714. try
  4715. {
  4716. check_C_ArrayIndex(val, index);
  4717. Console.WriteLine("C_ArrayIndex[" + index + "] failed");
  4718. return false;
  4719. }
  4720. catch
  4721. {
  4722. return true;
  4723. }
  4724. }
  4725. static bool check_C_ArrayIndex(C[] val, int index)
  4726. {
  4727. Expression<Func<C>> e =
  4728. Expression.Lambda<Func<C>>(
  4729. Expression.ArrayIndex(Expression.Constant(val, typeof(C[])),
  4730. Expression.Constant(index, typeof(int))),
  4731. new System.Collections.Generic.List<ParameterExpression>());
  4732. Func<C> f = e.Compile();
  4733. return object.Equals(f(), val[index]);
  4734. }
  4735. }
  4736. public static class Ext {
  4737. public static void StartCapture() {
  4738. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  4739. // m.Invoke(null, new object[] { "test.dll" });
  4740. }
  4741. public static void StopCapture() {
  4742. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  4743. // m.Invoke(null, new object[0]);
  4744. }
  4745. public static bool IsIntegralOrEnum(Type type) {
  4746. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  4747. case TypeCode.Byte:
  4748. case TypeCode.SByte:
  4749. case TypeCode.Int16:
  4750. case TypeCode.Int32:
  4751. case TypeCode.Int64:
  4752. case TypeCode.UInt16:
  4753. case TypeCode.UInt32:
  4754. case TypeCode.UInt64:
  4755. return true;
  4756. default:
  4757. return false;
  4758. }
  4759. }
  4760. public static bool IsFloating(Type type) {
  4761. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  4762. case TypeCode.Single:
  4763. case TypeCode.Double:
  4764. return true;
  4765. default:
  4766. return false;
  4767. }
  4768. }
  4769. public static Type GetNonNullableType(Type type) {
  4770. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  4771. type.GetGenericArguments()[0] :
  4772. type;
  4773. }
  4774. }
  4775. public interface I
  4776. {
  4777. void M();
  4778. }
  4779. public class C : IEquatable<C>, I
  4780. {
  4781. void I.M()
  4782. {
  4783. }
  4784. public override bool Equals(object o)
  4785. {
  4786. return o is C && Equals((C)o);
  4787. }
  4788. public bool Equals(C c)
  4789. {
  4790. return c != null;
  4791. }
  4792. public override int GetHashCode()
  4793. {
  4794. return 0;
  4795. }
  4796. }
  4797. public class D : C, IEquatable<D>
  4798. {
  4799. public int Val;
  4800. public D()
  4801. {
  4802. }
  4803. public D(int val)
  4804. {
  4805. Val = val;
  4806. }
  4807. public override bool Equals(object o)
  4808. {
  4809. return o is D && Equals((D)o);
  4810. }
  4811. public bool Equals(D d)
  4812. {
  4813. return d != null && d.Val == Val;
  4814. }
  4815. public override int GetHashCode()
  4816. {
  4817. return Val;
  4818. }
  4819. }
  4820. public enum E
  4821. {
  4822. A = 1, B = 2
  4823. }
  4824. public enum El : long
  4825. {
  4826. A, B, C
  4827. }
  4828. public struct S : IEquatable<S>
  4829. {
  4830. public override bool Equals(object o)
  4831. {
  4832. return (o is S) && Equals((S)o);
  4833. }
  4834. public bool Equals(S other)
  4835. {
  4836. return true;
  4837. }
  4838. public override int GetHashCode()
  4839. {
  4840. return 0;
  4841. }
  4842. }
  4843. public struct Sp : IEquatable<Sp>
  4844. {
  4845. public Sp(int i, double d)
  4846. {
  4847. I = i;
  4848. D = d;
  4849. }
  4850. public int I;
  4851. public double D;
  4852. public override bool Equals(object o)
  4853. {
  4854. return (o is Sp) && Equals((Sp)o);
  4855. }
  4856. public bool Equals(Sp other)
  4857. {
  4858. return other.I == I && other.D == D;
  4859. }
  4860. public override int GetHashCode()
  4861. {
  4862. return I.GetHashCode() ^ D.GetHashCode();
  4863. }
  4864. }
  4865. public struct Ss : IEquatable<Ss>
  4866. {
  4867. public Ss(S s)
  4868. {
  4869. Val = s;
  4870. }
  4871. public S Val;
  4872. public override bool Equals(object o)
  4873. {
  4874. return (o is Ss) && Equals((Ss)o);
  4875. }
  4876. public bool Equals(Ss other)
  4877. {
  4878. return other.Val.Equals(Val);
  4879. }
  4880. public override int GetHashCode()
  4881. {
  4882. return Val.GetHashCode();
  4883. }
  4884. }
  4885. public struct Sc : IEquatable<Sc>
  4886. {
  4887. public Sc(string s)
  4888. {
  4889. S = s;
  4890. }
  4891. public string S;
  4892. public override bool Equals(object o)
  4893. {
  4894. return (o is Sc) && Equals((Sc)o);
  4895. }
  4896. public bool Equals(Sc other)
  4897. {
  4898. return other.S == S;
  4899. }
  4900. public override int GetHashCode()
  4901. {
  4902. return S.GetHashCode();
  4903. }
  4904. }
  4905. public struct Scs : IEquatable<Scs>
  4906. {
  4907. public Scs(string s, S val)
  4908. {
  4909. S = s;
  4910. Val = val;
  4911. }
  4912. public string S;
  4913. public S Val;
  4914. public override bool Equals(object o)
  4915. {
  4916. return (o is Scs) && Equals((Scs)o);
  4917. }
  4918. public bool Equals(Scs other)
  4919. {
  4920. return other.S == S && other.Val.Equals(Val);
  4921. }
  4922. public override int GetHashCode()
  4923. {
  4924. return S.GetHashCode() ^ Val.GetHashCode();
  4925. }
  4926. }
  4927. }
  4928. //-------- Scenario 3150
  4929. namespace Scenario3150{
  4930. public class Test
  4931. {
  4932. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "D_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  4933. public static Expression D_ArrayIndex__() {
  4934. if(Main() != 0 ) {
  4935. throw new Exception();
  4936. } else {
  4937. return Expression.Constant(0);
  4938. }
  4939. }
  4940. public static int Main()
  4941. {
  4942. Ext.StartCapture();
  4943. bool success = false;
  4944. try
  4945. {
  4946. success = check_D_ArrayIndex();
  4947. }
  4948. finally
  4949. {
  4950. Ext.StopCapture();
  4951. }
  4952. return success ? 0 : 1;
  4953. }
  4954. static bool check_D_ArrayIndex()
  4955. {
  4956. return checkEx_D_ArrayIndex(null, -1) &
  4957. checkEx_D_ArrayIndex(null, 0) &
  4958. checkEx_D_ArrayIndex(null, 1) &
  4959. check_D_ArrayIndex(genArrD_ArrayIndex(0)) &
  4960. check_D_ArrayIndex(genArrD_ArrayIndex(1)) &
  4961. check_D_ArrayIndex(genArrD_ArrayIndex(5));
  4962. }
  4963. static D[] genArrD_ArrayIndex(int size)
  4964. {
  4965. D[] vals = new D[] { null, new D(), new D(0), new D(5) };
  4966. D[] result = new D[size];
  4967. for (int i = 0; i < size; i++)
  4968. {
  4969. result[i] = vals[i % vals.Length];
  4970. }
  4971. return result;
  4972. }
  4973. static bool check_D_ArrayIndex(D[] val)
  4974. {
  4975. bool success = checkEx_D_ArrayIndex(val, -1);
  4976. for (int i = 0; i < val.Length; i++)
  4977. {
  4978. success &= check_D_ArrayIndex(val, 0);
  4979. }
  4980. success &= checkEx_D_ArrayIndex(val, val.Length);
  4981. return success;
  4982. }
  4983. static bool checkEx_D_ArrayIndex(D[] val, int index)
  4984. {
  4985. try
  4986. {
  4987. check_D_ArrayIndex(val, index);
  4988. Console.WriteLine("D_ArrayIndex[" + index + "] failed");
  4989. return false;
  4990. }
  4991. catch
  4992. {
  4993. return true;
  4994. }
  4995. }
  4996. static bool check_D_ArrayIndex(D[] val, int index)
  4997. {
  4998. Expression<Func<D>> e =
  4999. Expression.Lambda<Func<D>>(
  5000. Expression.ArrayIndex(Expression.Constant(val, typeof(D[])),
  5001. Expression.Constant(index, typeof(int))),
  5002. new System.Collections.Generic.List<ParameterExpression>());
  5003. Func<D> f = e.Compile();
  5004. return object.Equals(f(), val[index]);
  5005. }
  5006. }
  5007. public static class Ext {
  5008. public static void StartCapture() {
  5009. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  5010. // m.Invoke(null, new object[] { "test.dll" });
  5011. }
  5012. public static void StopCapture() {
  5013. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  5014. // m.Invoke(null, new object[0]);
  5015. }
  5016. public static bool IsIntegralOrEnum(Type type) {
  5017. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  5018. case TypeCode.Byte:
  5019. case TypeCode.SByte:
  5020. case TypeCode.Int16:
  5021. case TypeCode.Int32:
  5022. case TypeCode.Int64:
  5023. case TypeCode.UInt16:
  5024. case TypeCode.UInt32:
  5025. case TypeCode.UInt64:
  5026. return true;
  5027. default:
  5028. return false;
  5029. }
  5030. }
  5031. public static bool IsFloating(Type type) {
  5032. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  5033. case TypeCode.Single:
  5034. case TypeCode.Double:
  5035. return true;
  5036. default:
  5037. return false;
  5038. }
  5039. }
  5040. public static Type GetNonNullableType(Type type) {
  5041. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  5042. type.GetGenericArguments()[0] :
  5043. type;
  5044. }
  5045. }
  5046. public interface I
  5047. {
  5048. void M();
  5049. }
  5050. public class C : IEquatable<C>, I
  5051. {
  5052. void I.M()
  5053. {
  5054. }
  5055. public override bool Equals(object o)
  5056. {
  5057. return o is C && Equals((C)o);
  5058. }
  5059. public bool Equals(C c)
  5060. {
  5061. return c != null;
  5062. }
  5063. public override int GetHashCode()
  5064. {
  5065. return 0;
  5066. }
  5067. }
  5068. public class D : C, IEquatable<D>
  5069. {
  5070. public int Val;
  5071. public D()
  5072. {
  5073. }
  5074. public D(int val)
  5075. {
  5076. Val = val;
  5077. }
  5078. public override bool Equals(object o)
  5079. {
  5080. return o is D && Equals((D)o);
  5081. }
  5082. public bool Equals(D d)
  5083. {
  5084. return d != null && d.Val == Val;
  5085. }
  5086. public override int GetHashCode()
  5087. {
  5088. return Val;
  5089. }
  5090. }
  5091. public enum E
  5092. {
  5093. A = 1, B = 2
  5094. }
  5095. public enum El : long
  5096. {
  5097. A, B, C
  5098. }
  5099. public struct S : IEquatable<S>
  5100. {
  5101. public override bool Equals(object o)
  5102. {
  5103. return (o is S) && Equals((S)o);
  5104. }
  5105. public bool Equals(S other)
  5106. {
  5107. return true;
  5108. }
  5109. public override int GetHashCode()
  5110. {
  5111. return 0;
  5112. }
  5113. }
  5114. public struct Sp : IEquatable<Sp>
  5115. {
  5116. public Sp(int i, double d)
  5117. {
  5118. I = i;
  5119. D = d;
  5120. }
  5121. public int I;
  5122. public double D;
  5123. public override bool Equals(object o)
  5124. {
  5125. return (o is Sp) && Equals((Sp)o);
  5126. }
  5127. public bool Equals(Sp other)
  5128. {
  5129. return other.I == I && other.D == D;
  5130. }
  5131. public override int GetHashCode()
  5132. {
  5133. return I.GetHashCode() ^ D.GetHashCode();
  5134. }
  5135. }
  5136. public struct Ss : IEquatable<Ss>
  5137. {
  5138. public Ss(S s)
  5139. {
  5140. Val = s;
  5141. }
  5142. public S Val;
  5143. public override bool Equals(object o)
  5144. {
  5145. return (o is Ss) && Equals((Ss)o);
  5146. }
  5147. public bool Equals(Ss other)
  5148. {
  5149. return other.Val.Equals(Val);
  5150. }
  5151. public override int GetHashCode()
  5152. {
  5153. return Val.GetHashCode();
  5154. }
  5155. }
  5156. public struct Sc : IEquatable<Sc>
  5157. {
  5158. public Sc(string s)
  5159. {
  5160. S = s;
  5161. }
  5162. public string S;
  5163. public override bool Equals(object o)
  5164. {
  5165. return (o is Sc) && Equals((Sc)o);
  5166. }
  5167. public bool Equals(Sc other)
  5168. {
  5169. return other.S == S;
  5170. }
  5171. public override int GetHashCode()
  5172. {
  5173. return S.GetHashCode();
  5174. }
  5175. }
  5176. public struct Scs : IEquatable<Scs>
  5177. {
  5178. public Scs(string s, S val)
  5179. {
  5180. S = s;
  5181. Val = val;
  5182. }
  5183. public string S;
  5184. public S Val;
  5185. public override bool Equals(object o)
  5186. {
  5187. return (o is Scs) && Equals((Scs)o);
  5188. }
  5189. public bool Equals(Scs other)
  5190. {
  5191. return other.S == S && other.Val.Equals(Val);
  5192. }
  5193. public override int GetHashCode()
  5194. {
  5195. return S.GetHashCode() ^ Val.GetHashCode();
  5196. }
  5197. }
  5198. }
  5199. //-------- Scenario 3151
  5200. namespace Scenario3151{
  5201. public class Test
  5202. {
  5203. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "T_ArrayIndex_object___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  5204. public static Expression T_ArrayIndex_object___() {
  5205. if(Main() != 0 ) {
  5206. throw new Exception();
  5207. } else {
  5208. return Expression.Constant(0);
  5209. }
  5210. }
  5211. public static int Main()
  5212. {
  5213. Ext.StartCapture();
  5214. bool success = false;
  5215. try
  5216. {
  5217. success = check_T_ArrayIndex<object>();
  5218. }
  5219. finally
  5220. {
  5221. Ext.StopCapture();
  5222. }
  5223. return success ? 0 : 1;
  5224. }
  5225. static bool check_T_ArrayIndex<T>()
  5226. {
  5227. return checkEx_T_ArrayIndex<T>(null, -1) &
  5228. checkEx_T_ArrayIndex<T>(null, 0) &
  5229. checkEx_T_ArrayIndex<T>(null, 1) &
  5230. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(0)) &
  5231. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(1)) &
  5232. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(5));
  5233. }
  5234. static T[] genArrT_ArrayIndex<T>(int size)
  5235. {
  5236. T[] vals = new T[] { default(T) };
  5237. T[] result = new T[size];
  5238. for (int i = 0; i < size; i++)
  5239. {
  5240. result[i] = vals[i % vals.Length];
  5241. }
  5242. return result;
  5243. }
  5244. static bool check_T_ArrayIndex<T>(T[] val)
  5245. {
  5246. bool success = checkEx_T_ArrayIndex<T>(val, -1);
  5247. for (int i = 0; i < val.Length; i++)
  5248. {
  5249. success &= check_T_ArrayIndex<T>(val, 0);
  5250. }
  5251. success &= checkEx_T_ArrayIndex<T>(val, val.Length);
  5252. return success;
  5253. }
  5254. static bool checkEx_T_ArrayIndex<T>(T[] val, int index)
  5255. {
  5256. try
  5257. {
  5258. check_T_ArrayIndex<T>(val, index);
  5259. Console.WriteLine("T_ArrayIndex[" + index + "] failed");
  5260. return false;
  5261. }
  5262. catch
  5263. {
  5264. return true;
  5265. }
  5266. }
  5267. static bool check_T_ArrayIndex<T>(T[] val, int index)
  5268. {
  5269. Expression<Func<T>> e =
  5270. Expression.Lambda<Func<T>>(
  5271. Expression.ArrayIndex(Expression.Constant(val, typeof(T[])),
  5272. Expression.Constant(index, typeof(int))),
  5273. new System.Collections.Generic.List<ParameterExpression>());
  5274. Func<T> f = e.Compile();
  5275. return object.Equals(f(), val[index]);
  5276. }
  5277. }
  5278. public static class Ext {
  5279. public static void StartCapture() {
  5280. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  5281. // m.Invoke(null, new object[] { "test.dll" });
  5282. }
  5283. public static void StopCapture() {
  5284. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  5285. // m.Invoke(null, new object[0]);
  5286. }
  5287. public static bool IsIntegralOrEnum(Type type) {
  5288. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  5289. case TypeCode.Byte:
  5290. case TypeCode.SByte:
  5291. case TypeCode.Int16:
  5292. case TypeCode.Int32:
  5293. case TypeCode.Int64:
  5294. case TypeCode.UInt16:
  5295. case TypeCode.UInt32:
  5296. case TypeCode.UInt64:
  5297. return true;
  5298. default:
  5299. return false;
  5300. }
  5301. }
  5302. public static bool IsFloating(Type type) {
  5303. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  5304. case TypeCode.Single:
  5305. case TypeCode.Double:
  5306. return true;
  5307. default:
  5308. return false;
  5309. }
  5310. }
  5311. public static Type GetNonNullableType(Type type) {
  5312. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  5313. type.GetGenericArguments()[0] :
  5314. type;
  5315. }
  5316. }
  5317. public interface I
  5318. {
  5319. void M();
  5320. }
  5321. public class C : IEquatable<C>, I
  5322. {
  5323. void I.M()
  5324. {
  5325. }
  5326. public override bool Equals(object o)
  5327. {
  5328. return o is C && Equals((C)o);
  5329. }
  5330. public bool Equals(C c)
  5331. {
  5332. return c != null;
  5333. }
  5334. public override int GetHashCode()
  5335. {
  5336. return 0;
  5337. }
  5338. }
  5339. public class D : C, IEquatable<D>
  5340. {
  5341. public int Val;
  5342. public D()
  5343. {
  5344. }
  5345. public D(int val)
  5346. {
  5347. Val = val;
  5348. }
  5349. public override bool Equals(object o)
  5350. {
  5351. return o is D && Equals((D)o);
  5352. }
  5353. public bool Equals(D d)
  5354. {
  5355. return d != null && d.Val == Val;
  5356. }
  5357. public override int GetHashCode()
  5358. {
  5359. return Val;
  5360. }
  5361. }
  5362. public enum E
  5363. {
  5364. A = 1, B = 2
  5365. }
  5366. public enum El : long
  5367. {
  5368. A, B, C
  5369. }
  5370. public struct S : IEquatable<S>
  5371. {
  5372. public override bool Equals(object o)
  5373. {
  5374. return (o is S) && Equals((S)o);
  5375. }
  5376. public bool Equals(S other)
  5377. {
  5378. return true;
  5379. }
  5380. public override int GetHashCode()
  5381. {
  5382. return 0;
  5383. }
  5384. }
  5385. public struct Sp : IEquatable<Sp>
  5386. {
  5387. public Sp(int i, double d)
  5388. {
  5389. I = i;
  5390. D = d;
  5391. }
  5392. public int I;
  5393. public double D;
  5394. public override bool Equals(object o)
  5395. {
  5396. return (o is Sp) && Equals((Sp)o);
  5397. }
  5398. public bool Equals(Sp other)
  5399. {
  5400. return other.I == I && other.D == D;
  5401. }
  5402. public override int GetHashCode()
  5403. {
  5404. return I.GetHashCode() ^ D.GetHashCode();
  5405. }
  5406. }
  5407. public struct Ss : IEquatable<Ss>
  5408. {
  5409. public Ss(S s)
  5410. {
  5411. Val = s;
  5412. }
  5413. public S Val;
  5414. public override bool Equals(object o)
  5415. {
  5416. return (o is Ss) && Equals((Ss)o);
  5417. }
  5418. public bool Equals(Ss other)
  5419. {
  5420. return other.Val.Equals(Val);
  5421. }
  5422. public override int GetHashCode()
  5423. {
  5424. return Val.GetHashCode();
  5425. }
  5426. }
  5427. public struct Sc : IEquatable<Sc>
  5428. {
  5429. public Sc(string s)
  5430. {
  5431. S = s;
  5432. }
  5433. public string S;
  5434. public override bool Equals(object o)
  5435. {
  5436. return (o is Sc) && Equals((Sc)o);
  5437. }
  5438. public bool Equals(Sc other)
  5439. {
  5440. return other.S == S;
  5441. }
  5442. public override int GetHashCode()
  5443. {
  5444. return S.GetHashCode();
  5445. }
  5446. }
  5447. public struct Scs : IEquatable<Scs>
  5448. {
  5449. public Scs(string s, S val)
  5450. {
  5451. S = s;
  5452. Val = val;
  5453. }
  5454. public string S;
  5455. public S Val;
  5456. public override bool Equals(object o)
  5457. {
  5458. return (o is Scs) && Equals((Scs)o);
  5459. }
  5460. public bool Equals(Scs other)
  5461. {
  5462. return other.S == S && other.Val.Equals(Val);
  5463. }
  5464. public override int GetHashCode()
  5465. {
  5466. return S.GetHashCode() ^ Val.GetHashCode();
  5467. }
  5468. }
  5469. }
  5470. //-------- Scenario 3152
  5471. namespace Scenario3152{
  5472. public class Test
  5473. {
  5474. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "T_ArrayIndex_C___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  5475. public static Expression T_ArrayIndex_C___() {
  5476. if(Main() != 0 ) {
  5477. throw new Exception();
  5478. } else {
  5479. return Expression.Constant(0);
  5480. }
  5481. }
  5482. public static int Main()
  5483. {
  5484. Ext.StartCapture();
  5485. bool success = false;
  5486. try
  5487. {
  5488. success = check_T_ArrayIndex<C>();
  5489. }
  5490. finally
  5491. {
  5492. Ext.StopCapture();
  5493. }
  5494. return success ? 0 : 1;
  5495. }
  5496. static bool check_T_ArrayIndex<T>()
  5497. {
  5498. return checkEx_T_ArrayIndex<T>(null, -1) &
  5499. checkEx_T_ArrayIndex<T>(null, 0) &
  5500. checkEx_T_ArrayIndex<T>(null, 1) &
  5501. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(0)) &
  5502. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(1)) &
  5503. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(5));
  5504. }
  5505. static T[] genArrT_ArrayIndex<T>(int size)
  5506. {
  5507. T[] vals = new T[] { default(T) };
  5508. T[] result = new T[size];
  5509. for (int i = 0; i < size; i++)
  5510. {
  5511. result[i] = vals[i % vals.Length];
  5512. }
  5513. return result;
  5514. }
  5515. static bool check_T_ArrayIndex<T>(T[] val)
  5516. {
  5517. bool success = checkEx_T_ArrayIndex<T>(val, -1);
  5518. for (int i = 0; i < val.Length; i++)
  5519. {
  5520. success &= check_T_ArrayIndex<T>(val, 0);
  5521. }
  5522. success &= checkEx_T_ArrayIndex<T>(val, val.Length);
  5523. return success;
  5524. }
  5525. static bool checkEx_T_ArrayIndex<T>(T[] val, int index)
  5526. {
  5527. try
  5528. {
  5529. check_T_ArrayIndex<T>(val, index);
  5530. Console.WriteLine("T_ArrayIndex[" + index + "] failed");
  5531. return false;
  5532. }
  5533. catch
  5534. {
  5535. return true;
  5536. }
  5537. }
  5538. static bool check_T_ArrayIndex<T>(T[] val, int index)
  5539. {
  5540. Expression<Func<T>> e =
  5541. Expression.Lambda<Func<T>>(
  5542. Expression.ArrayIndex(Expression.Constant(val, typeof(T[])),
  5543. Expression.Constant(index, typeof(int))),
  5544. new System.Collections.Generic.List<ParameterExpression>());
  5545. Func<T> f = e.Compile();
  5546. return object.Equals(f(), val[index]);
  5547. }
  5548. }
  5549. public static class Ext {
  5550. public static void StartCapture() {
  5551. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  5552. // m.Invoke(null, new object[] { "test.dll" });
  5553. }
  5554. public static void StopCapture() {
  5555. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  5556. // m.Invoke(null, new object[0]);
  5557. }
  5558. public static bool IsIntegralOrEnum(Type type) {
  5559. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  5560. case TypeCode.Byte:
  5561. case TypeCode.SByte:
  5562. case TypeCode.Int16:
  5563. case TypeCode.Int32:
  5564. case TypeCode.Int64:
  5565. case TypeCode.UInt16:
  5566. case TypeCode.UInt32:
  5567. case TypeCode.UInt64:
  5568. return true;
  5569. default:
  5570. return false;
  5571. }
  5572. }
  5573. public static bool IsFloating(Type type) {
  5574. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  5575. case TypeCode.Single:
  5576. case TypeCode.Double:
  5577. return true;
  5578. default:
  5579. return false;
  5580. }
  5581. }
  5582. public static Type GetNonNullableType(Type type) {
  5583. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  5584. type.GetGenericArguments()[0] :
  5585. type;
  5586. }
  5587. }
  5588. public interface I
  5589. {
  5590. void M();
  5591. }
  5592. public class C : IEquatable<C>, I
  5593. {
  5594. void I.M()
  5595. {
  5596. }
  5597. public override bool Equals(object o)
  5598. {
  5599. return o is C && Equals((C)o);
  5600. }
  5601. public bool Equals(C c)
  5602. {
  5603. return c != null;
  5604. }
  5605. public override int GetHashCode()
  5606. {
  5607. return 0;
  5608. }
  5609. }
  5610. public class D : C, IEquatable<D>
  5611. {
  5612. public int Val;
  5613. public D()
  5614. {
  5615. }
  5616. public D(int val)
  5617. {
  5618. Val = val;
  5619. }
  5620. public override bool Equals(object o)
  5621. {
  5622. return o is D && Equals((D)o);
  5623. }
  5624. public bool Equals(D d)
  5625. {
  5626. return d != null && d.Val == Val;
  5627. }
  5628. public override int GetHashCode()
  5629. {
  5630. return Val;
  5631. }
  5632. }
  5633. public enum E
  5634. {
  5635. A = 1, B = 2
  5636. }
  5637. public enum El : long
  5638. {
  5639. A, B, C
  5640. }
  5641. public struct S : IEquatable<S>
  5642. {
  5643. public override bool Equals(object o)
  5644. {
  5645. return (o is S) && Equals((S)o);
  5646. }
  5647. public bool Equals(S other)
  5648. {
  5649. return true;
  5650. }
  5651. public override int GetHashCode()
  5652. {
  5653. return 0;
  5654. }
  5655. }
  5656. public struct Sp : IEquatable<Sp>
  5657. {
  5658. public Sp(int i, double d)
  5659. {
  5660. I = i;
  5661. D = d;
  5662. }
  5663. public int I;
  5664. public double D;
  5665. public override bool Equals(object o)
  5666. {
  5667. return (o is Sp) && Equals((Sp)o);
  5668. }
  5669. public bool Equals(Sp other)
  5670. {
  5671. return other.I == I && other.D == D;
  5672. }
  5673. public override int GetHashCode()
  5674. {
  5675. return I.GetHashCode() ^ D.GetHashCode();
  5676. }
  5677. }
  5678. public struct Ss : IEquatable<Ss>
  5679. {
  5680. public Ss(S s)
  5681. {
  5682. Val = s;
  5683. }
  5684. public S Val;
  5685. public override bool Equals(object o)
  5686. {
  5687. return (o is Ss) && Equals((Ss)o);
  5688. }
  5689. public bool Equals(Ss other)
  5690. {
  5691. return other.Val.Equals(Val);
  5692. }
  5693. public override int GetHashCode()
  5694. {
  5695. return Val.GetHashCode();
  5696. }
  5697. }
  5698. public struct Sc : IEquatable<Sc>
  5699. {
  5700. public Sc(string s)
  5701. {
  5702. S = s;
  5703. }
  5704. public string S;
  5705. public override bool Equals(object o)
  5706. {
  5707. return (o is Sc) && Equals((Sc)o);
  5708. }
  5709. public bool Equals(Sc other)
  5710. {
  5711. return other.S == S;
  5712. }
  5713. public override int GetHashCode()
  5714. {
  5715. return S.GetHashCode();
  5716. }
  5717. }
  5718. public struct Scs : IEquatable<Scs>
  5719. {
  5720. public Scs(string s, S val)
  5721. {
  5722. S = s;
  5723. Val = val;
  5724. }
  5725. public string S;
  5726. public S Val;
  5727. public override bool Equals(object o)
  5728. {
  5729. return (o is Scs) && Equals((Scs)o);
  5730. }
  5731. public bool Equals(Scs other)
  5732. {
  5733. return other.S == S && other.Val.Equals(Val);
  5734. }
  5735. public override int GetHashCode()
  5736. {
  5737. return S.GetHashCode() ^ Val.GetHashCode();
  5738. }
  5739. }
  5740. }
  5741. //-------- Scenario 3153
  5742. namespace Scenario3153{
  5743. public class Test
  5744. {
  5745. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "T_ArrayIndex_S___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  5746. public static Expression T_ArrayIndex_S___() {
  5747. if(Main() != 0 ) {
  5748. throw new Exception();
  5749. } else {
  5750. return Expression.Constant(0);
  5751. }
  5752. }
  5753. public static int Main()
  5754. {
  5755. Ext.StartCapture();
  5756. bool success = false;
  5757. try
  5758. {
  5759. success = check_T_ArrayIndex<S>();
  5760. }
  5761. finally
  5762. {
  5763. Ext.StopCapture();
  5764. }
  5765. return success ? 0 : 1;
  5766. }
  5767. static bool check_T_ArrayIndex<T>()
  5768. {
  5769. return checkEx_T_ArrayIndex<T>(null, -1) &
  5770. checkEx_T_ArrayIndex<T>(null, 0) &
  5771. checkEx_T_ArrayIndex<T>(null, 1) &
  5772. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(0)) &
  5773. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(1)) &
  5774. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(5));
  5775. }
  5776. static T[] genArrT_ArrayIndex<T>(int size)
  5777. {
  5778. T[] vals = new T[] { default(T) };
  5779. T[] result = new T[size];
  5780. for (int i = 0; i < size; i++)
  5781. {
  5782. result[i] = vals[i % vals.Length];
  5783. }
  5784. return result;
  5785. }
  5786. static bool check_T_ArrayIndex<T>(T[] val)
  5787. {
  5788. bool success = checkEx_T_ArrayIndex<T>(val, -1);
  5789. for (int i = 0; i < val.Length; i++)
  5790. {
  5791. success &= check_T_ArrayIndex<T>(val, 0);
  5792. }
  5793. success &= checkEx_T_ArrayIndex<T>(val, val.Length);
  5794. return success;
  5795. }
  5796. static bool checkEx_T_ArrayIndex<T>(T[] val, int index)
  5797. {
  5798. try
  5799. {
  5800. check_T_ArrayIndex<T>(val, index);
  5801. Console.WriteLine("T_ArrayIndex[" + index + "] failed");
  5802. return false;
  5803. }
  5804. catch
  5805. {
  5806. return true;
  5807. }
  5808. }
  5809. static bool check_T_ArrayIndex<T>(T[] val, int index)
  5810. {
  5811. Expression<Func<T>> e =
  5812. Expression.Lambda<Func<T>>(
  5813. Expression.ArrayIndex(Expression.Constant(val, typeof(T[])),
  5814. Expression.Constant(index, typeof(int))),
  5815. new System.Collections.Generic.List<ParameterExpression>());
  5816. Func<T> f = e.Compile();
  5817. return object.Equals(f(), val[index]);
  5818. }
  5819. }
  5820. public static class Ext {
  5821. public static void StartCapture() {
  5822. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  5823. // m.Invoke(null, new object[] { "test.dll" });
  5824. }
  5825. public static void StopCapture() {
  5826. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  5827. // m.Invoke(null, new object[0]);
  5828. }
  5829. public static bool IsIntegralOrEnum(Type type) {
  5830. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  5831. case TypeCode.Byte:
  5832. case TypeCode.SByte:
  5833. case TypeCode.Int16:
  5834. case TypeCode.Int32:
  5835. case TypeCode.Int64:
  5836. case TypeCode.UInt16:
  5837. case TypeCode.UInt32:
  5838. case TypeCode.UInt64:
  5839. return true;
  5840. default:
  5841. return false;
  5842. }
  5843. }
  5844. public static bool IsFloating(Type type) {
  5845. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  5846. case TypeCode.Single:
  5847. case TypeCode.Double:
  5848. return true;
  5849. default:
  5850. return false;
  5851. }
  5852. }
  5853. public static Type GetNonNullableType(Type type) {
  5854. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  5855. type.GetGenericArguments()[0] :
  5856. type;
  5857. }
  5858. }
  5859. public interface I
  5860. {
  5861. void M();
  5862. }
  5863. public class C : IEquatable<C>, I
  5864. {
  5865. void I.M()
  5866. {
  5867. }
  5868. public override bool Equals(object o)
  5869. {
  5870. return o is C && Equals((C)o);
  5871. }
  5872. public bool Equals(C c)
  5873. {
  5874. return c != null;
  5875. }
  5876. public override int GetHashCode()
  5877. {
  5878. return 0;
  5879. }
  5880. }
  5881. public class D : C, IEquatable<D>
  5882. {
  5883. public int Val;
  5884. public D()
  5885. {
  5886. }
  5887. public D(int val)
  5888. {
  5889. Val = val;
  5890. }
  5891. public override bool Equals(object o)
  5892. {
  5893. return o is D && Equals((D)o);
  5894. }
  5895. public bool Equals(D d)
  5896. {
  5897. return d != null && d.Val == Val;
  5898. }
  5899. public override int GetHashCode()
  5900. {
  5901. return Val;
  5902. }
  5903. }
  5904. public enum E
  5905. {
  5906. A = 1, B = 2
  5907. }
  5908. public enum El : long
  5909. {
  5910. A, B, C
  5911. }
  5912. public struct S : IEquatable<S>
  5913. {
  5914. public override bool Equals(object o)
  5915. {
  5916. return (o is S) && Equals((S)o);
  5917. }
  5918. public bool Equals(S other)
  5919. {
  5920. return true;
  5921. }
  5922. public override int GetHashCode()
  5923. {
  5924. return 0;
  5925. }
  5926. }
  5927. public struct Sp : IEquatable<Sp>
  5928. {
  5929. public Sp(int i, double d)
  5930. {
  5931. I = i;
  5932. D = d;
  5933. }
  5934. public int I;
  5935. public double D;
  5936. public override bool Equals(object o)
  5937. {
  5938. return (o is Sp) && Equals((Sp)o);
  5939. }
  5940. public bool Equals(Sp other)
  5941. {
  5942. return other.I == I && other.D == D;
  5943. }
  5944. public override int GetHashCode()
  5945. {
  5946. return I.GetHashCode() ^ D.GetHashCode();
  5947. }
  5948. }
  5949. public struct Ss : IEquatable<Ss>
  5950. {
  5951. public Ss(S s)
  5952. {
  5953. Val = s;
  5954. }
  5955. public S Val;
  5956. public override bool Equals(object o)
  5957. {
  5958. return (o is Ss) && Equals((Ss)o);
  5959. }
  5960. public bool Equals(Ss other)
  5961. {
  5962. return other.Val.Equals(Val);
  5963. }
  5964. public override int GetHashCode()
  5965. {
  5966. return Val.GetHashCode();
  5967. }
  5968. }
  5969. public struct Sc : IEquatable<Sc>
  5970. {
  5971. public Sc(string s)
  5972. {
  5973. S = s;
  5974. }
  5975. public string S;
  5976. public override bool Equals(object o)
  5977. {
  5978. return (o is Sc) && Equals((Sc)o);
  5979. }
  5980. public bool Equals(Sc other)
  5981. {
  5982. return other.S == S;
  5983. }
  5984. public override int GetHashCode()
  5985. {
  5986. return S.GetHashCode();
  5987. }
  5988. }
  5989. public struct Scs : IEquatable<Scs>
  5990. {
  5991. public Scs(string s, S val)
  5992. {
  5993. S = s;
  5994. Val = val;
  5995. }
  5996. public string S;
  5997. public S Val;
  5998. public override bool Equals(object o)
  5999. {
  6000. return (o is Scs) && Equals((Scs)o);
  6001. }
  6002. public bool Equals(Scs other)
  6003. {
  6004. return other.S == S && other.Val.Equals(Val);
  6005. }
  6006. public override int GetHashCode()
  6007. {
  6008. return S.GetHashCode() ^ Val.GetHashCode();
  6009. }
  6010. }
  6011. }
  6012. //-------- Scenario 3154
  6013. namespace Scenario3154{
  6014. public class Test
  6015. {
  6016. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "T_ArrayIndex_Scs___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  6017. public static Expression T_ArrayIndex_Scs___() {
  6018. if(Main() != 0 ) {
  6019. throw new Exception();
  6020. } else {
  6021. return Expression.Constant(0);
  6022. }
  6023. }
  6024. public static int Main()
  6025. {
  6026. Ext.StartCapture();
  6027. bool success = false;
  6028. try
  6029. {
  6030. success = check_T_ArrayIndex<Scs>();
  6031. }
  6032. finally
  6033. {
  6034. Ext.StopCapture();
  6035. }
  6036. return success ? 0 : 1;
  6037. }
  6038. static bool check_T_ArrayIndex<T>()
  6039. {
  6040. return checkEx_T_ArrayIndex<T>(null, -1) &
  6041. checkEx_T_ArrayIndex<T>(null, 0) &
  6042. checkEx_T_ArrayIndex<T>(null, 1) &
  6043. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(0)) &
  6044. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(1)) &
  6045. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(5));
  6046. }
  6047. static T[] genArrT_ArrayIndex<T>(int size)
  6048. {
  6049. T[] vals = new T[] { default(T) };
  6050. T[] result = new T[size];
  6051. for (int i = 0; i < size; i++)
  6052. {
  6053. result[i] = vals[i % vals.Length];
  6054. }
  6055. return result;
  6056. }
  6057. static bool check_T_ArrayIndex<T>(T[] val)
  6058. {
  6059. bool success = checkEx_T_ArrayIndex<T>(val, -1);
  6060. for (int i = 0; i < val.Length; i++)
  6061. {
  6062. success &= check_T_ArrayIndex<T>(val, 0);
  6063. }
  6064. success &= checkEx_T_ArrayIndex<T>(val, val.Length);
  6065. return success;
  6066. }
  6067. static bool checkEx_T_ArrayIndex<T>(T[] val, int index)
  6068. {
  6069. try
  6070. {
  6071. check_T_ArrayIndex<T>(val, index);
  6072. Console.WriteLine("T_ArrayIndex[" + index + "] failed");
  6073. return false;
  6074. }
  6075. catch
  6076. {
  6077. return true;
  6078. }
  6079. }
  6080. static bool check_T_ArrayIndex<T>(T[] val, int index)
  6081. {
  6082. Expression<Func<T>> e =
  6083. Expression.Lambda<Func<T>>(
  6084. Expression.ArrayIndex(Expression.Constant(val, typeof(T[])),
  6085. Expression.Constant(index, typeof(int))),
  6086. new System.Collections.Generic.List<ParameterExpression>());
  6087. Func<T> f = e.Compile();
  6088. return object.Equals(f(), val[index]);
  6089. }
  6090. }
  6091. public static class Ext {
  6092. public static void StartCapture() {
  6093. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  6094. // m.Invoke(null, new object[] { "test.dll" });
  6095. }
  6096. public static void StopCapture() {
  6097. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  6098. // m.Invoke(null, new object[0]);
  6099. }
  6100. public static bool IsIntegralOrEnum(Type type) {
  6101. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  6102. case TypeCode.Byte:
  6103. case TypeCode.SByte:
  6104. case TypeCode.Int16:
  6105. case TypeCode.Int32:
  6106. case TypeCode.Int64:
  6107. case TypeCode.UInt16:
  6108. case TypeCode.UInt32:
  6109. case TypeCode.UInt64:
  6110. return true;
  6111. default:
  6112. return false;
  6113. }
  6114. }
  6115. public static bool IsFloating(Type type) {
  6116. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  6117. case TypeCode.Single:
  6118. case TypeCode.Double:
  6119. return true;
  6120. default:
  6121. return false;
  6122. }
  6123. }
  6124. public static Type GetNonNullableType(Type type) {
  6125. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  6126. type.GetGenericArguments()[0] :
  6127. type;
  6128. }
  6129. }
  6130. public interface I
  6131. {
  6132. void M();
  6133. }
  6134. public class C : IEquatable<C>, I
  6135. {
  6136. void I.M()
  6137. {
  6138. }
  6139. public override bool Equals(object o)
  6140. {
  6141. return o is C && Equals((C)o);
  6142. }
  6143. public bool Equals(C c)
  6144. {
  6145. return c != null;
  6146. }
  6147. public override int GetHashCode()
  6148. {
  6149. return 0;
  6150. }
  6151. }
  6152. public class D : C, IEquatable<D>
  6153. {
  6154. public int Val;
  6155. public D()
  6156. {
  6157. }
  6158. public D(int val)
  6159. {
  6160. Val = val;
  6161. }
  6162. public override bool Equals(object o)
  6163. {
  6164. return o is D && Equals((D)o);
  6165. }
  6166. public bool Equals(D d)
  6167. {
  6168. return d != null && d.Val == Val;
  6169. }
  6170. public override int GetHashCode()
  6171. {
  6172. return Val;
  6173. }
  6174. }
  6175. public enum E
  6176. {
  6177. A = 1, B = 2
  6178. }
  6179. public enum El : long
  6180. {
  6181. A, B, C
  6182. }
  6183. public struct S : IEquatable<S>
  6184. {
  6185. public override bool Equals(object o)
  6186. {
  6187. return (o is S) && Equals((S)o);
  6188. }
  6189. public bool Equals(S other)
  6190. {
  6191. return true;
  6192. }
  6193. public override int GetHashCode()
  6194. {
  6195. return 0;
  6196. }
  6197. }
  6198. public struct Sp : IEquatable<Sp>
  6199. {
  6200. public Sp(int i, double d)
  6201. {
  6202. I = i;
  6203. D = d;
  6204. }
  6205. public int I;
  6206. public double D;
  6207. public override bool Equals(object o)
  6208. {
  6209. return (o is Sp) && Equals((Sp)o);
  6210. }
  6211. public bool Equals(Sp other)
  6212. {
  6213. return other.I == I && other.D == D;
  6214. }
  6215. public override int GetHashCode()
  6216. {
  6217. return I.GetHashCode() ^ D.GetHashCode();
  6218. }
  6219. }
  6220. public struct Ss : IEquatable<Ss>
  6221. {
  6222. public Ss(S s)
  6223. {
  6224. Val = s;
  6225. }
  6226. public S Val;
  6227. public override bool Equals(object o)
  6228. {
  6229. return (o is Ss) && Equals((Ss)o);
  6230. }
  6231. public bool Equals(Ss other)
  6232. {
  6233. return other.Val.Equals(Val);
  6234. }
  6235. public override int GetHashCode()
  6236. {
  6237. return Val.GetHashCode();
  6238. }
  6239. }
  6240. public struct Sc : IEquatable<Sc>
  6241. {
  6242. public Sc(string s)
  6243. {
  6244. S = s;
  6245. }
  6246. public string S;
  6247. public override bool Equals(object o)
  6248. {
  6249. return (o is Sc) && Equals((Sc)o);
  6250. }
  6251. public bool Equals(Sc other)
  6252. {
  6253. return other.S == S;
  6254. }
  6255. public override int GetHashCode()
  6256. {
  6257. return S.GetHashCode();
  6258. }
  6259. }
  6260. public struct Scs : IEquatable<Scs>
  6261. {
  6262. public Scs(string s, S val)
  6263. {
  6264. S = s;
  6265. Val = val;
  6266. }
  6267. public string S;
  6268. public S Val;
  6269. public override bool Equals(object o)
  6270. {
  6271. return (o is Scs) && Equals((Scs)o);
  6272. }
  6273. public bool Equals(Scs other)
  6274. {
  6275. return other.S == S && other.Val.Equals(Val);
  6276. }
  6277. public override int GetHashCode()
  6278. {
  6279. return S.GetHashCode() ^ Val.GetHashCode();
  6280. }
  6281. }
  6282. }
  6283. //-------- Scenario 3155
  6284. namespace Scenario3155{
  6285. public class Test
  6286. {
  6287. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "T_ArrayIndex_E___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  6288. public static Expression T_ArrayIndex_E___() {
  6289. if(Main() != 0 ) {
  6290. throw new Exception();
  6291. } else {
  6292. return Expression.Constant(0);
  6293. }
  6294. }
  6295. public static int Main()
  6296. {
  6297. Ext.StartCapture();
  6298. bool success = false;
  6299. try
  6300. {
  6301. success = check_T_ArrayIndex<E>();
  6302. }
  6303. finally
  6304. {
  6305. Ext.StopCapture();
  6306. }
  6307. return success ? 0 : 1;
  6308. }
  6309. static bool check_T_ArrayIndex<T>()
  6310. {
  6311. return checkEx_T_ArrayIndex<T>(null, -1) &
  6312. checkEx_T_ArrayIndex<T>(null, 0) &
  6313. checkEx_T_ArrayIndex<T>(null, 1) &
  6314. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(0)) &
  6315. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(1)) &
  6316. check_T_ArrayIndex<T>(genArrT_ArrayIndex<T>(5));
  6317. }
  6318. static T[] genArrT_ArrayIndex<T>(int size)
  6319. {
  6320. T[] vals = new T[] { default(T) };
  6321. T[] result = new T[size];
  6322. for (int i = 0; i < size; i++)
  6323. {
  6324. result[i] = vals[i % vals.Length];
  6325. }
  6326. return result;
  6327. }
  6328. static bool check_T_ArrayIndex<T>(T[] val)
  6329. {
  6330. bool success = checkEx_T_ArrayIndex<T>(val, -1);
  6331. for (int i = 0; i < val.Length; i++)
  6332. {
  6333. success &= check_T_ArrayIndex<T>(val, 0);
  6334. }
  6335. success &= checkEx_T_ArrayIndex<T>(val, val.Length);
  6336. return success;
  6337. }
  6338. static bool checkEx_T_ArrayIndex<T>(T[] val, int index)
  6339. {
  6340. try
  6341. {
  6342. check_T_ArrayIndex<T>(val, index);
  6343. Console.WriteLine("T_ArrayIndex[" + index + "] failed");
  6344. return false;
  6345. }
  6346. catch
  6347. {
  6348. return true;
  6349. }
  6350. }
  6351. static bool check_T_ArrayIndex<T>(T[] val, int index)
  6352. {
  6353. Expression<Func<T>> e =
  6354. Expression.Lambda<Func<T>>(
  6355. Expression.ArrayIndex(Expression.Constant(val, typeof(T[])),
  6356. Expression.Constant(index, typeof(int))),
  6357. new System.Collections.Generic.List<ParameterExpression>());
  6358. Func<T> f = e.Compile();
  6359. return object.Equals(f(), val[index]);
  6360. }
  6361. }
  6362. public static class Ext {
  6363. public static void StartCapture() {
  6364. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  6365. // m.Invoke(null, new object[] { "test.dll" });
  6366. }
  6367. public static void StopCapture() {
  6368. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  6369. // m.Invoke(null, new object[0]);
  6370. }
  6371. public static bool IsIntegralOrEnum(Type type) {
  6372. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  6373. case TypeCode.Byte:
  6374. case TypeCode.SByte:
  6375. case TypeCode.Int16:
  6376. case TypeCode.Int32:
  6377. case TypeCode.Int64:
  6378. case TypeCode.UInt16:
  6379. case TypeCode.UInt32:
  6380. case TypeCode.UInt64:
  6381. return true;
  6382. default:
  6383. return false;
  6384. }
  6385. }
  6386. public static bool IsFloating(Type type) {
  6387. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  6388. case TypeCode.Single:
  6389. case TypeCode.Double:
  6390. return true;
  6391. default:
  6392. return false;
  6393. }
  6394. }
  6395. public static Type GetNonNullableType(Type type) {
  6396. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  6397. type.GetGenericArguments()[0] :
  6398. type;
  6399. }
  6400. }
  6401. public interface I
  6402. {
  6403. void M();
  6404. }
  6405. public class C : IEquatable<C>, I
  6406. {
  6407. void I.M()
  6408. {
  6409. }
  6410. public override bool Equals(object o)
  6411. {
  6412. return o is C && Equals((C)o);
  6413. }
  6414. public bool Equals(C c)
  6415. {
  6416. return c != null;
  6417. }
  6418. public override int GetHashCode()
  6419. {
  6420. return 0;
  6421. }
  6422. }
  6423. public class D : C, IEquatable<D>
  6424. {
  6425. public int Val;
  6426. public D()
  6427. {
  6428. }
  6429. public D(int val)
  6430. {
  6431. Val = val;
  6432. }
  6433. public override bool Equals(object o)
  6434. {
  6435. return o is D && Equals((D)o);
  6436. }
  6437. public bool Equals(D d)
  6438. {
  6439. return d != null && d.Val == Val;
  6440. }
  6441. public override int GetHashCode()
  6442. {
  6443. return Val;
  6444. }
  6445. }
  6446. public enum E
  6447. {
  6448. A = 1, B = 2
  6449. }
  6450. public enum El : long
  6451. {
  6452. A, B, C
  6453. }
  6454. public struct S : IEquatable<S>
  6455. {
  6456. public override bool Equals(object o)
  6457. {
  6458. return (o is S) && Equals((S)o);
  6459. }
  6460. public bool Equals(S other)
  6461. {
  6462. return true;
  6463. }
  6464. public override int GetHashCode()
  6465. {
  6466. return 0;
  6467. }
  6468. }
  6469. public struct Sp : IEquatable<Sp>
  6470. {
  6471. public Sp(int i, double d)
  6472. {
  6473. I = i;
  6474. D = d;
  6475. }
  6476. public int I;
  6477. public double D;
  6478. public override bool Equals(object o)
  6479. {
  6480. return (o is Sp) && Equals((Sp)o);
  6481. }
  6482. public bool Equals(Sp other)
  6483. {
  6484. return other.I == I && other.D == D;
  6485. }
  6486. public override int GetHashCode()
  6487. {
  6488. return I.GetHashCode() ^ D.GetHashCode();
  6489. }
  6490. }
  6491. public struct Ss : IEquatable<Ss>
  6492. {
  6493. public Ss(S s)
  6494. {
  6495. Val = s;
  6496. }
  6497. public S Val;
  6498. public override bool Equals(object o)
  6499. {
  6500. return (o is Ss) && Equals((Ss)o);
  6501. }
  6502. public bool Equals(Ss other)
  6503. {
  6504. return other.Val.Equals(Val);
  6505. }
  6506. public override int GetHashCode()
  6507. {
  6508. return Val.GetHashCode();
  6509. }
  6510. }
  6511. public struct Sc : IEquatable<Sc>
  6512. {
  6513. public Sc(string s)
  6514. {
  6515. S = s;
  6516. }
  6517. public string S;
  6518. public override bool Equals(object o)
  6519. {
  6520. return (o is Sc) && Equals((Sc)o);
  6521. }
  6522. public bool Equals(Sc other)
  6523. {
  6524. return other.S == S;
  6525. }
  6526. public override int GetHashCode()
  6527. {
  6528. return S.GetHashCode();
  6529. }
  6530. }
  6531. public struct Scs : IEquatable<Scs>
  6532. {
  6533. public Scs(string s, S val)
  6534. {
  6535. S = s;
  6536. Val = val;
  6537. }
  6538. public string S;
  6539. public S Val;
  6540. public override bool Equals(object o)
  6541. {
  6542. return (o is Scs) && Equals((Scs)o);
  6543. }
  6544. public bool Equals(Scs other)
  6545. {
  6546. return other.S == S && other.Val.Equals(Val);
  6547. }
  6548. public override int GetHashCode()
  6549. {
  6550. return S.GetHashCode() ^ Val.GetHashCode();
  6551. }
  6552. }
  6553. }
  6554. //-------- Scenario 3156
  6555. namespace Scenario3156{
  6556. public class Test
  6557. {
  6558. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Tc_ArrayIndex_object___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  6559. public static Expression Tc_ArrayIndex_object___() {
  6560. if(Main() != 0 ) {
  6561. throw new Exception();
  6562. } else {
  6563. return Expression.Constant(0);
  6564. }
  6565. }
  6566. public static int Main()
  6567. {
  6568. Ext.StartCapture();
  6569. bool success = false;
  6570. try
  6571. {
  6572. success = check_Tc_ArrayIndex<object>();
  6573. }
  6574. finally
  6575. {
  6576. Ext.StopCapture();
  6577. }
  6578. return success ? 0 : 1;
  6579. }
  6580. static bool check_Tc_ArrayIndex<Tc>() where Tc : class
  6581. {
  6582. return checkEx_Tc_ArrayIndex<Tc>(null, -1) &
  6583. checkEx_Tc_ArrayIndex<Tc>(null, 0) &
  6584. checkEx_Tc_ArrayIndex<Tc>(null, 1) &
  6585. check_Tc_ArrayIndex<Tc>(genArrTc_ArrayIndex<Tc>(0)) &
  6586. check_Tc_ArrayIndex<Tc>(genArrTc_ArrayIndex<Tc>(1)) &
  6587. check_Tc_ArrayIndex<Tc>(genArrTc_ArrayIndex<Tc>(5));
  6588. }
  6589. static Tc[] genArrTc_ArrayIndex<Tc>(int size) where Tc : class
  6590. {
  6591. Tc[] vals = new Tc[] { null, default(Tc) };
  6592. Tc[] result = new Tc[size];
  6593. for (int i = 0; i < size; i++)
  6594. {
  6595. result[i] = vals[i % vals.Length];
  6596. }
  6597. return result;
  6598. }
  6599. static bool check_Tc_ArrayIndex<Tc>(Tc[] val) where Tc : class
  6600. {
  6601. bool success = checkEx_Tc_ArrayIndex<Tc>(val, -1);
  6602. for (int i = 0; i < val.Length; i++)
  6603. {
  6604. success &= check_Tc_ArrayIndex<Tc>(val, 0);
  6605. }
  6606. success &= checkEx_Tc_ArrayIndex<Tc>(val, val.Length);
  6607. return success;
  6608. }
  6609. static bool checkEx_Tc_ArrayIndex<Tc>(Tc[] val, int index) where Tc : class
  6610. {
  6611. try
  6612. {
  6613. check_Tc_ArrayIndex<Tc>(val, index);
  6614. Console.WriteLine("Tc_ArrayIndex[" + index + "] failed");
  6615. return false;
  6616. }
  6617. catch
  6618. {
  6619. return true;
  6620. }
  6621. }
  6622. static bool check_Tc_ArrayIndex<Tc>(Tc[] val, int index) where Tc : class
  6623. {
  6624. Expression<Func<Tc>> e =
  6625. Expression.Lambda<Func<Tc>>(
  6626. Expression.ArrayIndex(Expression.Constant(val, typeof(Tc[])),
  6627. Expression.Constant(index, typeof(int))),
  6628. new System.Collections.Generic.List<ParameterExpression>());
  6629. Func<Tc> f = e.Compile();
  6630. return object.Equals(f(), val[index]);
  6631. }
  6632. }
  6633. public static class Ext {
  6634. public static void StartCapture() {
  6635. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  6636. // m.Invoke(null, new object[] { "test.dll" });
  6637. }
  6638. public static void StopCapture() {
  6639. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  6640. // m.Invoke(null, new object[0]);
  6641. }
  6642. public static bool IsIntegralOrEnum(Type type) {
  6643. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  6644. case TypeCode.Byte:
  6645. case TypeCode.SByte:
  6646. case TypeCode.Int16:
  6647. case TypeCode.Int32:
  6648. case TypeCode.Int64:
  6649. case TypeCode.UInt16:
  6650. case TypeCode.UInt32:
  6651. case TypeCode.UInt64:
  6652. return true;
  6653. default:
  6654. return false;
  6655. }
  6656. }
  6657. public static bool IsFloating(Type type) {
  6658. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  6659. case TypeCode.Single:
  6660. case TypeCode.Double:
  6661. return true;
  6662. default:
  6663. return false;
  6664. }
  6665. }
  6666. public static Type GetNonNullableType(Type type) {
  6667. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  6668. type.GetGenericArguments()[0] :
  6669. type;
  6670. }
  6671. }
  6672. public interface I
  6673. {
  6674. void M();
  6675. }
  6676. public class C : IEquatable<C>, I
  6677. {
  6678. void I.M()
  6679. {
  6680. }
  6681. public override bool Equals(object o)
  6682. {
  6683. return o is C && Equals((C)o);
  6684. }
  6685. public bool Equals(C c)
  6686. {
  6687. return c != null;
  6688. }
  6689. public override int GetHashCode()
  6690. {
  6691. return 0;
  6692. }
  6693. }
  6694. public class D : C, IEquatable<D>
  6695. {
  6696. public int Val;
  6697. public D()
  6698. {
  6699. }
  6700. public D(int val)
  6701. {
  6702. Val = val;
  6703. }
  6704. public override bool Equals(object o)
  6705. {
  6706. return o is D && Equals((D)o);
  6707. }
  6708. public bool Equals(D d)
  6709. {
  6710. return d != null && d.Val == Val;
  6711. }
  6712. public override int GetHashCode()
  6713. {
  6714. return Val;
  6715. }
  6716. }
  6717. public enum E
  6718. {
  6719. A = 1, B = 2
  6720. }
  6721. public enum El : long
  6722. {
  6723. A, B, C
  6724. }
  6725. public struct S : IEquatable<S>
  6726. {
  6727. public override bool Equals(object o)
  6728. {
  6729. return (o is S) && Equals((S)o);
  6730. }
  6731. public bool Equals(S other)
  6732. {
  6733. return true;
  6734. }
  6735. public override int GetHashCode()
  6736. {
  6737. return 0;
  6738. }
  6739. }
  6740. public struct Sp : IEquatable<Sp>
  6741. {
  6742. public Sp(int i, double d)
  6743. {
  6744. I = i;
  6745. D = d;
  6746. }
  6747. public int I;
  6748. public double D;
  6749. public override bool Equals(object o)
  6750. {
  6751. return (o is Sp) && Equals((Sp)o);
  6752. }
  6753. public bool Equals(Sp other)
  6754. {
  6755. return other.I == I && other.D == D;
  6756. }
  6757. public override int GetHashCode()
  6758. {
  6759. return I.GetHashCode() ^ D.GetHashCode();
  6760. }
  6761. }
  6762. public struct Ss : IEquatable<Ss>
  6763. {
  6764. public Ss(S s)
  6765. {
  6766. Val = s;
  6767. }
  6768. public S Val;
  6769. public override bool Equals(object o)
  6770. {
  6771. return (o is Ss) && Equals((Ss)o);
  6772. }
  6773. public bool Equals(Ss other)
  6774. {
  6775. return other.Val.Equals(Val);
  6776. }
  6777. public override int GetHashCode()
  6778. {
  6779. return Val.GetHashCode();
  6780. }
  6781. }
  6782. public struct Sc : IEquatable<Sc>
  6783. {
  6784. public Sc(string s)
  6785. {
  6786. S = s;
  6787. }
  6788. public string S;
  6789. public override bool Equals(object o)
  6790. {
  6791. return (o is Sc) && Equals((Sc)o);
  6792. }
  6793. public bool Equals(Sc other)
  6794. {
  6795. return other.S == S;
  6796. }
  6797. public override int GetHashCode()
  6798. {
  6799. return S.GetHashCode();
  6800. }
  6801. }
  6802. public struct Scs : IEquatable<Scs>
  6803. {
  6804. public Scs(string s, S val)
  6805. {
  6806. S = s;
  6807. Val = val;
  6808. }
  6809. public string S;
  6810. public S Val;
  6811. public override bool Equals(object o)
  6812. {
  6813. return (o is Scs) && Equals((Scs)o);
  6814. }
  6815. public bool Equals(Scs other)
  6816. {
  6817. return other.S == S && other.Val.Equals(Val);
  6818. }
  6819. public override int GetHashCode()
  6820. {
  6821. return S.GetHashCode() ^ Val.GetHashCode();
  6822. }
  6823. }
  6824. }
  6825. //-------- Scenario 3157
  6826. namespace Scenario3157{
  6827. public class Test
  6828. {
  6829. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Tc_ArrayIndex_C___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  6830. public static Expression Tc_ArrayIndex_C___() {
  6831. if(Main() != 0 ) {
  6832. throw new Exception();
  6833. } else {
  6834. return Expression.Constant(0);
  6835. }
  6836. }
  6837. public static int Main()
  6838. {
  6839. Ext.StartCapture();
  6840. bool success = false;
  6841. try
  6842. {
  6843. success = check_Tc_ArrayIndex<C>();
  6844. }
  6845. finally
  6846. {
  6847. Ext.StopCapture();
  6848. }
  6849. return success ? 0 : 1;
  6850. }
  6851. static bool check_Tc_ArrayIndex<Tc>() where Tc : class
  6852. {
  6853. return checkEx_Tc_ArrayIndex<Tc>(null, -1) &
  6854. checkEx_Tc_ArrayIndex<Tc>(null, 0) &
  6855. checkEx_Tc_ArrayIndex<Tc>(null, 1) &
  6856. check_Tc_ArrayIndex<Tc>(genArrTc_ArrayIndex<Tc>(0)) &
  6857. check_Tc_ArrayIndex<Tc>(genArrTc_ArrayIndex<Tc>(1)) &
  6858. check_Tc_ArrayIndex<Tc>(genArrTc_ArrayIndex<Tc>(5));
  6859. }
  6860. static Tc[] genArrTc_ArrayIndex<Tc>(int size) where Tc : class
  6861. {
  6862. Tc[] vals = new Tc[] { null, default(Tc) };
  6863. Tc[] result = new Tc[size];
  6864. for (int i = 0; i < size; i++)
  6865. {
  6866. result[i] = vals[i % vals.Length];
  6867. }
  6868. return result;
  6869. }
  6870. static bool check_Tc_ArrayIndex<Tc>(Tc[] val) where Tc : class
  6871. {
  6872. bool success = checkEx_Tc_ArrayIndex<Tc>(val, -1);
  6873. for (int i = 0; i < val.Length; i++)
  6874. {
  6875. success &= check_Tc_ArrayIndex<Tc>(val, 0);
  6876. }
  6877. success &= checkEx_Tc_ArrayIndex<Tc>(val, val.Length);
  6878. return success;
  6879. }
  6880. static bool checkEx_Tc_ArrayIndex<Tc>(Tc[] val, int index) where Tc : class
  6881. {
  6882. try
  6883. {
  6884. check_Tc_ArrayIndex<Tc>(val, index);
  6885. Console.WriteLine("Tc_ArrayIndex[" + index + "] failed");
  6886. return false;
  6887. }
  6888. catch
  6889. {
  6890. return true;
  6891. }
  6892. }
  6893. static bool check_Tc_ArrayIndex<Tc>(Tc[] val, int index) where Tc : class
  6894. {
  6895. Expression<Func<Tc>> e =
  6896. Expression.Lambda<Func<Tc>>(
  6897. Expression.ArrayIndex(Expression.Constant(val, typeof(Tc[])),
  6898. Expression.Constant(index, typeof(int))),
  6899. new System.Collections.Generic.List<ParameterExpression>());
  6900. Func<Tc> f = e.Compile();
  6901. return object.Equals(f(), val[index]);
  6902. }
  6903. }
  6904. public static class Ext {
  6905. public static void StartCapture() {
  6906. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  6907. // m.Invoke(null, new object[] { "test.dll" });
  6908. }
  6909. public static void StopCapture() {
  6910. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  6911. // m.Invoke(null, new object[0]);
  6912. }
  6913. public static bool IsIntegralOrEnum(Type type) {
  6914. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  6915. case TypeCode.Byte:
  6916. case TypeCode.SByte:
  6917. case TypeCode.Int16:
  6918. case TypeCode.Int32:
  6919. case TypeCode.Int64:
  6920. case TypeCode.UInt16:
  6921. case TypeCode.UInt32:
  6922. case TypeCode.UInt64:
  6923. return true;
  6924. default:
  6925. return false;
  6926. }
  6927. }
  6928. public static bool IsFloating(Type type) {
  6929. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  6930. case TypeCode.Single:
  6931. case TypeCode.Double:
  6932. return true;
  6933. default:
  6934. return false;
  6935. }
  6936. }
  6937. public static Type GetNonNullableType(Type type) {
  6938. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  6939. type.GetGenericArguments()[0] :
  6940. type;
  6941. }
  6942. }
  6943. public interface I
  6944. {
  6945. void M();
  6946. }
  6947. public class C : IEquatable<C>, I
  6948. {
  6949. void I.M()
  6950. {
  6951. }
  6952. public override bool Equals(object o)
  6953. {
  6954. return o is C && Equals((C)o);
  6955. }
  6956. public bool Equals(C c)
  6957. {
  6958. return c != null;
  6959. }
  6960. public override int GetHashCode()
  6961. {
  6962. return 0;
  6963. }
  6964. }
  6965. public class D : C, IEquatable<D>
  6966. {
  6967. public int Val;
  6968. public D()
  6969. {
  6970. }
  6971. public D(int val)
  6972. {
  6973. Val = val;
  6974. }
  6975. public override bool Equals(object o)
  6976. {
  6977. return o is D && Equals((D)o);
  6978. }
  6979. public bool Equals(D d)
  6980. {
  6981. return d != null && d.Val == Val;
  6982. }
  6983. public override int GetHashCode()
  6984. {
  6985. return Val;
  6986. }
  6987. }
  6988. public enum E
  6989. {
  6990. A = 1, B = 2
  6991. }
  6992. public enum El : long
  6993. {
  6994. A, B, C
  6995. }
  6996. public struct S : IEquatable<S>
  6997. {
  6998. public override bool Equals(object o)
  6999. {
  7000. return (o is S) && Equals((S)o);
  7001. }
  7002. public bool Equals(S other)
  7003. {
  7004. return true;
  7005. }
  7006. public override int GetHashCode()
  7007. {
  7008. return 0;
  7009. }
  7010. }
  7011. public struct Sp : IEquatable<Sp>
  7012. {
  7013. public Sp(int i, double d)
  7014. {
  7015. I = i;
  7016. D = d;
  7017. }
  7018. public int I;
  7019. public double D;
  7020. public override bool Equals(object o)
  7021. {
  7022. return (o is Sp) && Equals((Sp)o);
  7023. }
  7024. public bool Equals(Sp other)
  7025. {
  7026. return other.I == I && other.D == D;
  7027. }
  7028. public override int GetHashCode()
  7029. {
  7030. return I.GetHashCode() ^ D.GetHashCode();
  7031. }
  7032. }
  7033. public struct Ss : IEquatable<Ss>
  7034. {
  7035. public Ss(S s)
  7036. {
  7037. Val = s;
  7038. }
  7039. public S Val;
  7040. public override bool Equals(object o)
  7041. {
  7042. return (o is Ss) && Equals((Ss)o);
  7043. }
  7044. public bool Equals(Ss other)
  7045. {
  7046. return other.Val.Equals(Val);
  7047. }
  7048. public override int GetHashCode()
  7049. {
  7050. return Val.GetHashCode();
  7051. }
  7052. }
  7053. public struct Sc : IEquatable<Sc>
  7054. {
  7055. public Sc(string s)
  7056. {
  7057. S = s;
  7058. }
  7059. public string S;
  7060. public override bool Equals(object o)
  7061. {
  7062. return (o is Sc) && Equals((Sc)o);
  7063. }
  7064. public bool Equals(Sc other)
  7065. {
  7066. return other.S == S;
  7067. }
  7068. public override int GetHashCode()
  7069. {
  7070. return S.GetHashCode();
  7071. }
  7072. }
  7073. public struct Scs : IEquatable<Scs>
  7074. {
  7075. public Scs(string s, S val)
  7076. {
  7077. S = s;
  7078. Val = val;
  7079. }
  7080. public string S;
  7081. public S Val;
  7082. public override bool Equals(object o)
  7083. {
  7084. return (o is Scs) && Equals((Scs)o);
  7085. }
  7086. public bool Equals(Scs other)
  7087. {
  7088. return other.S == S && other.Val.Equals(Val);
  7089. }
  7090. public override int GetHashCode()
  7091. {
  7092. return S.GetHashCode() ^ Val.GetHashCode();
  7093. }
  7094. }
  7095. }
  7096. //-------- Scenario 3158
  7097. namespace Scenario3158{
  7098. public class Test
  7099. {
  7100. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Tcn_ArrayIndex_object___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  7101. public static Expression Tcn_ArrayIndex_object___() {
  7102. if(Main() != 0 ) {
  7103. throw new Exception();
  7104. } else {
  7105. return Expression.Constant(0);
  7106. }
  7107. }
  7108. public static int Main()
  7109. {
  7110. Ext.StartCapture();
  7111. bool success = false;
  7112. try
  7113. {
  7114. success = check_Tcn_ArrayIndex<object>();
  7115. }
  7116. finally
  7117. {
  7118. Ext.StopCapture();
  7119. }
  7120. return success ? 0 : 1;
  7121. }
  7122. static bool check_Tcn_ArrayIndex<Tcn>() where Tcn : class, new()
  7123. {
  7124. return checkEx_Tcn_ArrayIndex<Tcn>(null, -1) &
  7125. checkEx_Tcn_ArrayIndex<Tcn>(null, 0) &
  7126. checkEx_Tcn_ArrayIndex<Tcn>(null, 1) &
  7127. check_Tcn_ArrayIndex<Tcn>(genArrTcn_ArrayIndex<Tcn>(0)) &
  7128. check_Tcn_ArrayIndex<Tcn>(genArrTcn_ArrayIndex<Tcn>(1)) &
  7129. check_Tcn_ArrayIndex<Tcn>(genArrTcn_ArrayIndex<Tcn>(5));
  7130. }
  7131. static Tcn[] genArrTcn_ArrayIndex<Tcn>(int size) where Tcn : class, new()
  7132. {
  7133. Tcn[] vals = new Tcn[] { null, default(Tcn), new Tcn() };
  7134. Tcn[] result = new Tcn[size];
  7135. for (int i = 0; i < size; i++)
  7136. {
  7137. result[i] = vals[i % vals.Length];
  7138. }
  7139. return result;
  7140. }
  7141. static bool check_Tcn_ArrayIndex<Tcn>(Tcn[] val) where Tcn : class, new()
  7142. {
  7143. bool success = checkEx_Tcn_ArrayIndex<Tcn>(val, -1);
  7144. for (int i = 0; i < val.Length; i++)
  7145. {
  7146. success &= check_Tcn_ArrayIndex<Tcn>(val, 0);
  7147. }
  7148. success &= checkEx_Tcn_ArrayIndex<Tcn>(val, val.Length);
  7149. return success;
  7150. }
  7151. static bool checkEx_Tcn_ArrayIndex<Tcn>(Tcn[] val, int index) where Tcn : class, new()
  7152. {
  7153. try
  7154. {
  7155. check_Tcn_ArrayIndex<Tcn>(val, index);
  7156. Console.WriteLine("Tcn_ArrayIndex[" + index + "] failed");
  7157. return false;
  7158. }
  7159. catch
  7160. {
  7161. return true;
  7162. }
  7163. }
  7164. static bool check_Tcn_ArrayIndex<Tcn>(Tcn[] val, int index) where Tcn : class, new()
  7165. {
  7166. Expression<Func<Tcn>> e =
  7167. Expression.Lambda<Func<Tcn>>(
  7168. Expression.ArrayIndex(Expression.Constant(val, typeof(Tcn[])),
  7169. Expression.Constant(index, typeof(int))),
  7170. new System.Collections.Generic.List<ParameterExpression>());
  7171. Func<Tcn> f = e.Compile();
  7172. return object.Equals(f(), val[index]);
  7173. }
  7174. }
  7175. public static class Ext {
  7176. public static void StartCapture() {
  7177. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  7178. // m.Invoke(null, new object[] { "test.dll" });
  7179. }
  7180. public static void StopCapture() {
  7181. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  7182. // m.Invoke(null, new object[0]);
  7183. }
  7184. public static bool IsIntegralOrEnum(Type type) {
  7185. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  7186. case TypeCode.Byte:
  7187. case TypeCode.SByte:
  7188. case TypeCode.Int16:
  7189. case TypeCode.Int32:
  7190. case TypeCode.Int64:
  7191. case TypeCode.UInt16:
  7192. case TypeCode.UInt32:
  7193. case TypeCode.UInt64:
  7194. return true;
  7195. default:
  7196. return false;
  7197. }
  7198. }
  7199. public static bool IsFloating(Type type) {
  7200. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  7201. case TypeCode.Single:
  7202. case TypeCode.Double:
  7203. return true;
  7204. default:
  7205. return false;
  7206. }
  7207. }
  7208. public static Type GetNonNullableType(Type type) {
  7209. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  7210. type.GetGenericArguments()[0] :
  7211. type;
  7212. }
  7213. }
  7214. public interface I
  7215. {
  7216. void M();
  7217. }
  7218. public class C : IEquatable<C>, I
  7219. {
  7220. void I.M()
  7221. {
  7222. }
  7223. public override bool Equals(object o)
  7224. {
  7225. return o is C && Equals((C)o);
  7226. }
  7227. public bool Equals(C c)
  7228. {
  7229. return c != null;
  7230. }
  7231. public override int GetHashCode()
  7232. {
  7233. return 0;
  7234. }
  7235. }
  7236. public class D : C, IEquatable<D>
  7237. {
  7238. public int Val;
  7239. public D()
  7240. {
  7241. }
  7242. public D(int val)
  7243. {
  7244. Val = val;
  7245. }
  7246. public override bool Equals(object o)
  7247. {
  7248. return o is D && Equals((D)o);
  7249. }
  7250. public bool Equals(D d)
  7251. {
  7252. return d != null && d.Val == Val;
  7253. }
  7254. public override int GetHashCode()
  7255. {
  7256. return Val;
  7257. }
  7258. }
  7259. public enum E
  7260. {
  7261. A = 1, B = 2
  7262. }
  7263. public enum El : long
  7264. {
  7265. A, B, C
  7266. }
  7267. public struct S : IEquatable<S>
  7268. {
  7269. public override bool Equals(object o)
  7270. {
  7271. return (o is S) && Equals((S)o);
  7272. }
  7273. public bool Equals(S other)
  7274. {
  7275. return true;
  7276. }
  7277. public override int GetHashCode()
  7278. {
  7279. return 0;
  7280. }
  7281. }
  7282. public struct Sp : IEquatable<Sp>
  7283. {
  7284. public Sp(int i, double d)
  7285. {
  7286. I = i;
  7287. D = d;
  7288. }
  7289. public int I;
  7290. public double D;
  7291. public override bool Equals(object o)
  7292. {
  7293. return (o is Sp) && Equals((Sp)o);
  7294. }
  7295. public bool Equals(Sp other)
  7296. {
  7297. return other.I == I && other.D == D;
  7298. }
  7299. public override int GetHashCode()
  7300. {
  7301. return I.GetHashCode() ^ D.GetHashCode();
  7302. }
  7303. }
  7304. public struct Ss : IEquatable<Ss>
  7305. {
  7306. public Ss(S s)
  7307. {
  7308. Val = s;
  7309. }
  7310. public S Val;
  7311. public override bool Equals(object o)
  7312. {
  7313. return (o is Ss) && Equals((Ss)o);
  7314. }
  7315. public bool Equals(Ss other)
  7316. {
  7317. return other.Val.Equals(Val);
  7318. }
  7319. public override int GetHashCode()
  7320. {
  7321. return Val.GetHashCode();
  7322. }
  7323. }
  7324. public struct Sc : IEquatable<Sc>
  7325. {
  7326. public Sc(string s)
  7327. {
  7328. S = s;
  7329. }
  7330. public string S;
  7331. public override bool Equals(object o)
  7332. {
  7333. return (o is Sc) && Equals((Sc)o);
  7334. }
  7335. public bool Equals(Sc other)
  7336. {
  7337. return other.S == S;
  7338. }
  7339. public override int GetHashCode()
  7340. {
  7341. return S.GetHashCode();
  7342. }
  7343. }
  7344. public struct Scs : IEquatable<Scs>
  7345. {
  7346. public Scs(string s, S val)
  7347. {
  7348. S = s;
  7349. Val = val;
  7350. }
  7351. public string S;
  7352. public S Val;
  7353. public override bool Equals(object o)
  7354. {
  7355. return (o is Scs) && Equals((Scs)o);
  7356. }
  7357. public bool Equals(Scs other)
  7358. {
  7359. return other.S == S && other.Val.Equals(Val);
  7360. }
  7361. public override int GetHashCode()
  7362. {
  7363. return S.GetHashCode() ^ Val.GetHashCode();
  7364. }
  7365. }
  7366. }
  7367. //-------- Scenario 3159
  7368. namespace Scenario3159{
  7369. public class Test
  7370. {
  7371. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Tcn_ArrayIndex_C___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  7372. public static Expression Tcn_ArrayIndex_C___() {
  7373. if(Main() != 0 ) {
  7374. throw new Exception();
  7375. } else {
  7376. return Expression.Constant(0);
  7377. }
  7378. }
  7379. public static int Main()
  7380. {
  7381. Ext.StartCapture();
  7382. bool success = false;
  7383. try
  7384. {
  7385. success = check_Tcn_ArrayIndex<C>();
  7386. }
  7387. finally
  7388. {
  7389. Ext.StopCapture();
  7390. }
  7391. return success ? 0 : 1;
  7392. }
  7393. static bool check_Tcn_ArrayIndex<Tcn>() where Tcn : class, new()
  7394. {
  7395. return checkEx_Tcn_ArrayIndex<Tcn>(null, -1) &
  7396. checkEx_Tcn_ArrayIndex<Tcn>(null, 0) &
  7397. checkEx_Tcn_ArrayIndex<Tcn>(null, 1) &
  7398. check_Tcn_ArrayIndex<Tcn>(genArrTcn_ArrayIndex<Tcn>(0)) &
  7399. check_Tcn_ArrayIndex<Tcn>(genArrTcn_ArrayIndex<Tcn>(1)) &
  7400. check_Tcn_ArrayIndex<Tcn>(genArrTcn_ArrayIndex<Tcn>(5));
  7401. }
  7402. static Tcn[] genArrTcn_ArrayIndex<Tcn>(int size) where Tcn : class, new()
  7403. {
  7404. Tcn[] vals = new Tcn[] { null, default(Tcn), new Tcn() };
  7405. Tcn[] result = new Tcn[size];
  7406. for (int i = 0; i < size; i++)
  7407. {
  7408. result[i] = vals[i % vals.Length];
  7409. }
  7410. return result;
  7411. }
  7412. static bool check_Tcn_ArrayIndex<Tcn>(Tcn[] val) where Tcn : class, new()
  7413. {
  7414. bool success = checkEx_Tcn_ArrayIndex<Tcn>(val, -1);
  7415. for (int i = 0; i < val.Length; i++)
  7416. {
  7417. success &= check_Tcn_ArrayIndex<Tcn>(val, 0);
  7418. }
  7419. success &= checkEx_Tcn_ArrayIndex<Tcn>(val, val.Length);
  7420. return success;
  7421. }
  7422. static bool checkEx_Tcn_ArrayIndex<Tcn>(Tcn[] val, int index) where Tcn : class, new()
  7423. {
  7424. try
  7425. {
  7426. check_Tcn_ArrayIndex<Tcn>(val, index);
  7427. Console.WriteLine("Tcn_ArrayIndex[" + index + "] failed");
  7428. return false;
  7429. }
  7430. catch
  7431. {
  7432. return true;
  7433. }
  7434. }
  7435. static bool check_Tcn_ArrayIndex<Tcn>(Tcn[] val, int index) where Tcn : class, new()
  7436. {
  7437. Expression<Func<Tcn>> e =
  7438. Expression.Lambda<Func<Tcn>>(
  7439. Expression.ArrayIndex(Expression.Constant(val, typeof(Tcn[])),
  7440. Expression.Constant(index, typeof(int))),
  7441. new System.Collections.Generic.List<ParameterExpression>());
  7442. Func<Tcn> f = e.Compile();
  7443. return object.Equals(f(), val[index]);
  7444. }
  7445. }
  7446. public static class Ext {
  7447. public static void StartCapture() {
  7448. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  7449. // m.Invoke(null, new object[] { "test.dll" });
  7450. }
  7451. public static void StopCapture() {
  7452. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  7453. // m.Invoke(null, new object[0]);
  7454. }
  7455. public static bool IsIntegralOrEnum(Type type) {
  7456. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  7457. case TypeCode.Byte:
  7458. case TypeCode.SByte:
  7459. case TypeCode.Int16:
  7460. case TypeCode.Int32:
  7461. case TypeCode.Int64:
  7462. case TypeCode.UInt16:
  7463. case TypeCode.UInt32:
  7464. case TypeCode.UInt64:
  7465. return true;
  7466. default:
  7467. return false;
  7468. }
  7469. }
  7470. public static bool IsFloating(Type type) {
  7471. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  7472. case TypeCode.Single:
  7473. case TypeCode.Double:
  7474. return true;
  7475. default:
  7476. return false;
  7477. }
  7478. }
  7479. public static Type GetNonNullableType(Type type) {
  7480. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  7481. type.GetGenericArguments()[0] :
  7482. type;
  7483. }
  7484. }
  7485. public interface I
  7486. {
  7487. void M();
  7488. }
  7489. public class C : IEquatable<C>, I
  7490. {
  7491. void I.M()
  7492. {
  7493. }
  7494. public override bool Equals(object o)
  7495. {
  7496. return o is C && Equals((C)o);
  7497. }
  7498. public bool Equals(C c)
  7499. {
  7500. return c != null;
  7501. }
  7502. public override int GetHashCode()
  7503. {
  7504. return 0;
  7505. }
  7506. }
  7507. public class D : C, IEquatable<D>
  7508. {
  7509. public int Val;
  7510. public D()
  7511. {
  7512. }
  7513. public D(int val)
  7514. {
  7515. Val = val;
  7516. }
  7517. public override bool Equals(object o)
  7518. {
  7519. return o is D && Equals((D)o);
  7520. }
  7521. public bool Equals(D d)
  7522. {
  7523. return d != null && d.Val == Val;
  7524. }
  7525. public override int GetHashCode()
  7526. {
  7527. return Val;
  7528. }
  7529. }
  7530. public enum E
  7531. {
  7532. A = 1, B = 2
  7533. }
  7534. public enum El : long
  7535. {
  7536. A, B, C
  7537. }
  7538. public struct S : IEquatable<S>
  7539. {
  7540. public override bool Equals(object o)
  7541. {
  7542. return (o is S) && Equals((S)o);
  7543. }
  7544. public bool Equals(S other)
  7545. {
  7546. return true;
  7547. }
  7548. public override int GetHashCode()
  7549. {
  7550. return 0;
  7551. }
  7552. }
  7553. public struct Sp : IEquatable<Sp>
  7554. {
  7555. public Sp(int i, double d)
  7556. {
  7557. I = i;
  7558. D = d;
  7559. }
  7560. public int I;
  7561. public double D;
  7562. public override bool Equals(object o)
  7563. {
  7564. return (o is Sp) && Equals((Sp)o);
  7565. }
  7566. public bool Equals(Sp other)
  7567. {
  7568. return other.I == I && other.D == D;
  7569. }
  7570. public override int GetHashCode()
  7571. {
  7572. return I.GetHashCode() ^ D.GetHashCode();
  7573. }
  7574. }
  7575. public struct Ss : IEquatable<Ss>
  7576. {
  7577. public Ss(S s)
  7578. {
  7579. Val = s;
  7580. }
  7581. public S Val;
  7582. public override bool Equals(object o)
  7583. {
  7584. return (o is Ss) && Equals((Ss)o);
  7585. }
  7586. public bool Equals(Ss other)
  7587. {
  7588. return other.Val.Equals(Val);
  7589. }
  7590. public override int GetHashCode()
  7591. {
  7592. return Val.GetHashCode();
  7593. }
  7594. }
  7595. public struct Sc : IEquatable<Sc>
  7596. {
  7597. public Sc(string s)
  7598. {
  7599. S = s;
  7600. }
  7601. public string S;
  7602. public override bool Equals(object o)
  7603. {
  7604. return (o is Sc) && Equals((Sc)o);
  7605. }
  7606. public bool Equals(Sc other)
  7607. {
  7608. return other.S == S;
  7609. }
  7610. public override int GetHashCode()
  7611. {
  7612. return S.GetHashCode();
  7613. }
  7614. }
  7615. public struct Scs : IEquatable<Scs>
  7616. {
  7617. public Scs(string s, S val)
  7618. {
  7619. S = s;
  7620. Val = val;
  7621. }
  7622. public string S;
  7623. public S Val;
  7624. public override bool Equals(object o)
  7625. {
  7626. return (o is Scs) && Equals((Scs)o);
  7627. }
  7628. public bool Equals(Scs other)
  7629. {
  7630. return other.S == S && other.Val.Equals(Val);
  7631. }
  7632. public override int GetHashCode()
  7633. {
  7634. return S.GetHashCode() ^ Val.GetHashCode();
  7635. }
  7636. }
  7637. }
  7638. //-------- Scenario 3160
  7639. namespace Scenario3160{
  7640. public class Test
  7641. {
  7642. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "TC_ArrayIndex_C_a__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  7643. public static Expression TC_ArrayIndex_C_a__() {
  7644. if(Main() != 0 ) {
  7645. throw new Exception();
  7646. } else {
  7647. return Expression.Constant(0);
  7648. }
  7649. }
  7650. public static int Main()
  7651. {
  7652. Ext.StartCapture();
  7653. bool success = false;
  7654. try
  7655. {
  7656. success = check_TC_ArrayIndex<C>();
  7657. }
  7658. finally
  7659. {
  7660. Ext.StopCapture();
  7661. }
  7662. return success ? 0 : 1;
  7663. }
  7664. static bool check_TC_ArrayIndex<TC>() where TC : C
  7665. {
  7666. return checkEx_TC_ArrayIndex<TC>(null, -1) &
  7667. checkEx_TC_ArrayIndex<TC>(null, 0) &
  7668. checkEx_TC_ArrayIndex<TC>(null, 1) &
  7669. check_TC_ArrayIndex<TC>(genArrTC_ArrayIndex<TC>(0)) &
  7670. check_TC_ArrayIndex<TC>(genArrTC_ArrayIndex<TC>(1)) &
  7671. check_TC_ArrayIndex<TC>(genArrTC_ArrayIndex<TC>(5));
  7672. }
  7673. static TC[] genArrTC_ArrayIndex<TC>(int size) where TC : C
  7674. {
  7675. TC[] vals = new TC[] { null, default(TC), (TC)new C() };
  7676. TC[] result = new TC[size];
  7677. for (int i = 0; i < size; i++)
  7678. {
  7679. result[i] = vals[i % vals.Length];
  7680. }
  7681. return result;
  7682. }
  7683. static bool check_TC_ArrayIndex<TC>(TC[] val) where TC : C
  7684. {
  7685. bool success = checkEx_TC_ArrayIndex<TC>(val, -1);
  7686. for (int i = 0; i < val.Length; i++)
  7687. {
  7688. success &= check_TC_ArrayIndex<TC>(val, 0);
  7689. }
  7690. success &= checkEx_TC_ArrayIndex<TC>(val, val.Length);
  7691. return success;
  7692. }
  7693. static bool checkEx_TC_ArrayIndex<TC>(TC[] val, int index) where TC : C
  7694. {
  7695. try
  7696. {
  7697. check_TC_ArrayIndex<TC>(val, index);
  7698. Console.WriteLine("TC_ArrayIndex[" + index + "] failed");
  7699. return false;
  7700. }
  7701. catch
  7702. {
  7703. return true;
  7704. }
  7705. }
  7706. static bool check_TC_ArrayIndex<TC>(TC[] val, int index) where TC : C
  7707. {
  7708. Expression<Func<TC>> e =
  7709. Expression.Lambda<Func<TC>>(
  7710. Expression.ArrayIndex(Expression.Constant(val, typeof(TC[])),
  7711. Expression.Constant(index, typeof(int))),
  7712. new System.Collections.Generic.List<ParameterExpression>());
  7713. Func<TC> f = e.Compile();
  7714. return object.Equals(f(), val[index]);
  7715. }
  7716. }
  7717. public static class Ext {
  7718. public static void StartCapture() {
  7719. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  7720. // m.Invoke(null, new object[] { "test.dll" });
  7721. }
  7722. public static void StopCapture() {
  7723. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  7724. // m.Invoke(null, new object[0]);
  7725. }
  7726. public static bool IsIntegralOrEnum(Type type) {
  7727. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  7728. case TypeCode.Byte:
  7729. case TypeCode.SByte:
  7730. case TypeCode.Int16:
  7731. case TypeCode.Int32:
  7732. case TypeCode.Int64:
  7733. case TypeCode.UInt16:
  7734. case TypeCode.UInt32:
  7735. case TypeCode.UInt64:
  7736. return true;
  7737. default:
  7738. return false;
  7739. }
  7740. }
  7741. public static bool IsFloating(Type type) {
  7742. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  7743. case TypeCode.Single:
  7744. case TypeCode.Double:
  7745. return true;
  7746. default:
  7747. return false;
  7748. }
  7749. }
  7750. public static Type GetNonNullableType(Type type) {
  7751. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  7752. type.GetGenericArguments()[0] :
  7753. type;
  7754. }
  7755. }
  7756. public interface I
  7757. {
  7758. void M();
  7759. }
  7760. public class C : IEquatable<C>, I
  7761. {
  7762. void I.M()
  7763. {
  7764. }
  7765. public override bool Equals(object o)
  7766. {
  7767. return o is C && Equals((C)o);
  7768. }
  7769. public bool Equals(C c)
  7770. {
  7771. return c != null;
  7772. }
  7773. public override int GetHashCode()
  7774. {
  7775. return 0;
  7776. }
  7777. }
  7778. public class D : C, IEquatable<D>
  7779. {
  7780. public int Val;
  7781. public D()
  7782. {
  7783. }
  7784. public D(int val)
  7785. {
  7786. Val = val;
  7787. }
  7788. public override bool Equals(object o)
  7789. {
  7790. return o is D && Equals((D)o);
  7791. }
  7792. public bool Equals(D d)
  7793. {
  7794. return d != null && d.Val == Val;
  7795. }
  7796. public override int GetHashCode()
  7797. {
  7798. return Val;
  7799. }
  7800. }
  7801. public enum E
  7802. {
  7803. A = 1, B = 2
  7804. }
  7805. public enum El : long
  7806. {
  7807. A, B, C
  7808. }
  7809. public struct S : IEquatable<S>
  7810. {
  7811. public override bool Equals(object o)
  7812. {
  7813. return (o is S) && Equals((S)o);
  7814. }
  7815. public bool Equals(S other)
  7816. {
  7817. return true;
  7818. }
  7819. public override int GetHashCode()
  7820. {
  7821. return 0;
  7822. }
  7823. }
  7824. public struct Sp : IEquatable<Sp>
  7825. {
  7826. public Sp(int i, double d)
  7827. {
  7828. I = i;
  7829. D = d;
  7830. }
  7831. public int I;
  7832. public double D;
  7833. public override bool Equals(object o)
  7834. {
  7835. return (o is Sp) && Equals((Sp)o);
  7836. }
  7837. public bool Equals(Sp other)
  7838. {
  7839. return other.I == I && other.D == D;
  7840. }
  7841. public override int GetHashCode()
  7842. {
  7843. return I.GetHashCode() ^ D.GetHashCode();
  7844. }
  7845. }
  7846. public struct Ss : IEquatable<Ss>
  7847. {
  7848. public Ss(S s)
  7849. {
  7850. Val = s;
  7851. }
  7852. public S Val;
  7853. public override bool Equals(object o)
  7854. {
  7855. return (o is Ss) && Equals((Ss)o);
  7856. }
  7857. public bool Equals(Ss other)
  7858. {
  7859. return other.Val.Equals(Val);
  7860. }
  7861. public override int GetHashCode()
  7862. {
  7863. return Val.GetHashCode();
  7864. }
  7865. }
  7866. public struct Sc : IEquatable<Sc>
  7867. {
  7868. public Sc(string s)
  7869. {
  7870. S = s;
  7871. }
  7872. public string S;
  7873. public override bool Equals(object o)
  7874. {
  7875. return (o is Sc) && Equals((Sc)o);
  7876. }
  7877. public bool Equals(Sc other)
  7878. {
  7879. return other.S == S;
  7880. }
  7881. public override int GetHashCode()
  7882. {
  7883. return S.GetHashCode();
  7884. }
  7885. }
  7886. public struct Scs : IEquatable<Scs>
  7887. {
  7888. public Scs(string s, S val)
  7889. {
  7890. S = s;
  7891. Val = val;
  7892. }
  7893. public string S;
  7894. public S Val;
  7895. public override bool Equals(object o)
  7896. {
  7897. return (o is Scs) && Equals((Scs)o);
  7898. }
  7899. public bool Equals(Scs other)
  7900. {
  7901. return other.S == S && other.Val.Equals(Val);
  7902. }
  7903. public override int GetHashCode()
  7904. {
  7905. return S.GetHashCode() ^ Val.GetHashCode();
  7906. }
  7907. }
  7908. }
  7909. //-------- Scenario 3161
  7910. namespace Scenario3161{
  7911. public class Test
  7912. {
  7913. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "TCn_ArrayIndex_C_a__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  7914. public static Expression TCn_ArrayIndex_C_a__() {
  7915. if(Main() != 0 ) {
  7916. throw new Exception();
  7917. } else {
  7918. return Expression.Constant(0);
  7919. }
  7920. }
  7921. public static int Main()
  7922. {
  7923. Ext.StartCapture();
  7924. bool success = false;
  7925. try
  7926. {
  7927. success = check_TCn_ArrayIndex<C>();
  7928. }
  7929. finally
  7930. {
  7931. Ext.StopCapture();
  7932. }
  7933. return success ? 0 : 1;
  7934. }
  7935. static bool check_TCn_ArrayIndex<TCn>() where TCn : C, new()
  7936. {
  7937. return checkEx_TCn_ArrayIndex<TCn>(null, -1) &
  7938. checkEx_TCn_ArrayIndex<TCn>(null, 0) &
  7939. checkEx_TCn_ArrayIndex<TCn>(null, 1) &
  7940. check_TCn_ArrayIndex<TCn>(genArrTCn_ArrayIndex<TCn>(0)) &
  7941. check_TCn_ArrayIndex<TCn>(genArrTCn_ArrayIndex<TCn>(1)) &
  7942. check_TCn_ArrayIndex<TCn>(genArrTCn_ArrayIndex<TCn>(5));
  7943. }
  7944. static TCn[] genArrTCn_ArrayIndex<TCn>(int size) where TCn : C, new()
  7945. {
  7946. TCn[] vals = new TCn[] { null, default(TCn), new TCn(), (TCn)new C() };
  7947. TCn[] result = new TCn[size];
  7948. for (int i = 0; i < size; i++)
  7949. {
  7950. result[i] = vals[i % vals.Length];
  7951. }
  7952. return result;
  7953. }
  7954. static bool check_TCn_ArrayIndex<TCn>(TCn[] val) where TCn : C, new()
  7955. {
  7956. bool success = checkEx_TCn_ArrayIndex<TCn>(val, -1);
  7957. for (int i = 0; i < val.Length; i++)
  7958. {
  7959. success &= check_TCn_ArrayIndex<TCn>(val, 0);
  7960. }
  7961. success &= checkEx_TCn_ArrayIndex<TCn>(val, val.Length);
  7962. return success;
  7963. }
  7964. static bool checkEx_TCn_ArrayIndex<TCn>(TCn[] val, int index) where TCn : C, new()
  7965. {
  7966. try
  7967. {
  7968. check_TCn_ArrayIndex<TCn>(val, index);
  7969. Console.WriteLine("TCn_ArrayIndex[" + index + "] failed");
  7970. return false;
  7971. }
  7972. catch
  7973. {
  7974. return true;
  7975. }
  7976. }
  7977. static bool check_TCn_ArrayIndex<TCn>(TCn[] val, int index) where TCn : C, new()
  7978. {
  7979. Expression<Func<TCn>> e =
  7980. Expression.Lambda<Func<TCn>>(
  7981. Expression.ArrayIndex(Expression.Constant(val, typeof(TCn[])),
  7982. Expression.Constant(index, typeof(int))),
  7983. new System.Collections.Generic.List<ParameterExpression>());
  7984. Func<TCn> f = e.Compile();
  7985. return object.Equals(f(), val[index]);
  7986. }
  7987. }
  7988. public static class Ext {
  7989. public static void StartCapture() {
  7990. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  7991. // m.Invoke(null, new object[] { "test.dll" });
  7992. }
  7993. public static void StopCapture() {
  7994. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  7995. // m.Invoke(null, new object[0]);
  7996. }
  7997. public static bool IsIntegralOrEnum(Type type) {
  7998. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  7999. case TypeCode.Byte:
  8000. case TypeCode.SByte:
  8001. case TypeCode.Int16:
  8002. case TypeCode.Int32:
  8003. case TypeCode.Int64:
  8004. case TypeCode.UInt16:
  8005. case TypeCode.UInt32:
  8006. case TypeCode.UInt64:
  8007. return true;
  8008. default:
  8009. return false;
  8010. }
  8011. }
  8012. public static bool IsFloating(Type type) {
  8013. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8014. case TypeCode.Single:
  8015. case TypeCode.Double:
  8016. return true;
  8017. default:
  8018. return false;
  8019. }
  8020. }
  8021. public static Type GetNonNullableType(Type type) {
  8022. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  8023. type.GetGenericArguments()[0] :
  8024. type;
  8025. }
  8026. }
  8027. public interface I
  8028. {
  8029. void M();
  8030. }
  8031. public class C : IEquatable<C>, I
  8032. {
  8033. void I.M()
  8034. {
  8035. }
  8036. public override bool Equals(object o)
  8037. {
  8038. return o is C && Equals((C)o);
  8039. }
  8040. public bool Equals(C c)
  8041. {
  8042. return c != null;
  8043. }
  8044. public override int GetHashCode()
  8045. {
  8046. return 0;
  8047. }
  8048. }
  8049. public class D : C, IEquatable<D>
  8050. {
  8051. public int Val;
  8052. public D()
  8053. {
  8054. }
  8055. public D(int val)
  8056. {
  8057. Val = val;
  8058. }
  8059. public override bool Equals(object o)
  8060. {
  8061. return o is D && Equals((D)o);
  8062. }
  8063. public bool Equals(D d)
  8064. {
  8065. return d != null && d.Val == Val;
  8066. }
  8067. public override int GetHashCode()
  8068. {
  8069. return Val;
  8070. }
  8071. }
  8072. public enum E
  8073. {
  8074. A = 1, B = 2
  8075. }
  8076. public enum El : long
  8077. {
  8078. A, B, C
  8079. }
  8080. public struct S : IEquatable<S>
  8081. {
  8082. public override bool Equals(object o)
  8083. {
  8084. return (o is S) && Equals((S)o);
  8085. }
  8086. public bool Equals(S other)
  8087. {
  8088. return true;
  8089. }
  8090. public override int GetHashCode()
  8091. {
  8092. return 0;
  8093. }
  8094. }
  8095. public struct Sp : IEquatable<Sp>
  8096. {
  8097. public Sp(int i, double d)
  8098. {
  8099. I = i;
  8100. D = d;
  8101. }
  8102. public int I;
  8103. public double D;
  8104. public override bool Equals(object o)
  8105. {
  8106. return (o is Sp) && Equals((Sp)o);
  8107. }
  8108. public bool Equals(Sp other)
  8109. {
  8110. return other.I == I && other.D == D;
  8111. }
  8112. public override int GetHashCode()
  8113. {
  8114. return I.GetHashCode() ^ D.GetHashCode();
  8115. }
  8116. }
  8117. public struct Ss : IEquatable<Ss>
  8118. {
  8119. public Ss(S s)
  8120. {
  8121. Val = s;
  8122. }
  8123. public S Val;
  8124. public override bool Equals(object o)
  8125. {
  8126. return (o is Ss) && Equals((Ss)o);
  8127. }
  8128. public bool Equals(Ss other)
  8129. {
  8130. return other.Val.Equals(Val);
  8131. }
  8132. public override int GetHashCode()
  8133. {
  8134. return Val.GetHashCode();
  8135. }
  8136. }
  8137. public struct Sc : IEquatable<Sc>
  8138. {
  8139. public Sc(string s)
  8140. {
  8141. S = s;
  8142. }
  8143. public string S;
  8144. public override bool Equals(object o)
  8145. {
  8146. return (o is Sc) && Equals((Sc)o);
  8147. }
  8148. public bool Equals(Sc other)
  8149. {
  8150. return other.S == S;
  8151. }
  8152. public override int GetHashCode()
  8153. {
  8154. return S.GetHashCode();
  8155. }
  8156. }
  8157. public struct Scs : IEquatable<Scs>
  8158. {
  8159. public Scs(string s, S val)
  8160. {
  8161. S = s;
  8162. Val = val;
  8163. }
  8164. public string S;
  8165. public S Val;
  8166. public override bool Equals(object o)
  8167. {
  8168. return (o is Scs) && Equals((Scs)o);
  8169. }
  8170. public bool Equals(Scs other)
  8171. {
  8172. return other.S == S && other.Val.Equals(Val);
  8173. }
  8174. public override int GetHashCode()
  8175. {
  8176. return S.GetHashCode() ^ Val.GetHashCode();
  8177. }
  8178. }
  8179. }
  8180. //-------- Scenario 3162
  8181. namespace Scenario3162{
  8182. public class Test
  8183. {
  8184. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Delegate_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  8185. public static Expression Delegate_ArrayIndex__() {
  8186. if(Main() != 0 ) {
  8187. throw new Exception();
  8188. } else {
  8189. return Expression.Constant(0);
  8190. }
  8191. }
  8192. public static int Main()
  8193. {
  8194. Ext.StartCapture();
  8195. bool success = false;
  8196. try
  8197. {
  8198. success = check_Delegate_ArrayIndex();
  8199. }
  8200. finally
  8201. {
  8202. Ext.StopCapture();
  8203. }
  8204. return success ? 0 : 1;
  8205. }
  8206. static bool check_Delegate_ArrayIndex()
  8207. {
  8208. return checkEx_Delegate_ArrayIndex(null, -1) &
  8209. checkEx_Delegate_ArrayIndex(null, 0) &
  8210. checkEx_Delegate_ArrayIndex(null, 1) &
  8211. check_Delegate_ArrayIndex(genArrDelegate_ArrayIndex(0)) &
  8212. check_Delegate_ArrayIndex(genArrDelegate_ArrayIndex(1)) &
  8213. check_Delegate_ArrayIndex(genArrDelegate_ArrayIndex(5));
  8214. }
  8215. static Delegate[] genArrDelegate_ArrayIndex(int size)
  8216. {
  8217. Delegate[] vals = new Delegate[] { null, (Func<object>)delegate() { return null; }, (Func<int, int>)delegate(int i) { return i + 1; }, (Action<object>)delegate { } };
  8218. Delegate[] result = new Delegate[size];
  8219. for (int i = 0; i < size; i++)
  8220. {
  8221. result[i] = vals[i % vals.Length];
  8222. }
  8223. return result;
  8224. }
  8225. static bool check_Delegate_ArrayIndex(Delegate[] val)
  8226. {
  8227. bool success = checkEx_Delegate_ArrayIndex(val, -1);
  8228. for (int i = 0; i < val.Length; i++)
  8229. {
  8230. success &= check_Delegate_ArrayIndex(val, 0);
  8231. }
  8232. success &= checkEx_Delegate_ArrayIndex(val, val.Length);
  8233. return success;
  8234. }
  8235. static bool checkEx_Delegate_ArrayIndex(Delegate[] val, int index)
  8236. {
  8237. try
  8238. {
  8239. check_Delegate_ArrayIndex(val, index);
  8240. Console.WriteLine("Delegate_ArrayIndex[" + index + "] failed");
  8241. return false;
  8242. }
  8243. catch
  8244. {
  8245. return true;
  8246. }
  8247. }
  8248. static bool check_Delegate_ArrayIndex(Delegate[] val, int index)
  8249. {
  8250. Expression<Func<Delegate>> e =
  8251. Expression.Lambda<Func<Delegate>>(
  8252. Expression.ArrayIndex(Expression.Constant(val, typeof(Delegate[])),
  8253. Expression.Constant(index, typeof(int))),
  8254. new System.Collections.Generic.List<ParameterExpression>());
  8255. Func<Delegate> f = e.Compile();
  8256. return object.Equals(f(), val[index]);
  8257. }
  8258. }
  8259. public static class Ext {
  8260. public static void StartCapture() {
  8261. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  8262. // m.Invoke(null, new object[] { "test.dll" });
  8263. }
  8264. public static void StopCapture() {
  8265. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  8266. // m.Invoke(null, new object[0]);
  8267. }
  8268. public static bool IsIntegralOrEnum(Type type) {
  8269. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8270. case TypeCode.Byte:
  8271. case TypeCode.SByte:
  8272. case TypeCode.Int16:
  8273. case TypeCode.Int32:
  8274. case TypeCode.Int64:
  8275. case TypeCode.UInt16:
  8276. case TypeCode.UInt32:
  8277. case TypeCode.UInt64:
  8278. return true;
  8279. default:
  8280. return false;
  8281. }
  8282. }
  8283. public static bool IsFloating(Type type) {
  8284. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8285. case TypeCode.Single:
  8286. case TypeCode.Double:
  8287. return true;
  8288. default:
  8289. return false;
  8290. }
  8291. }
  8292. public static Type GetNonNullableType(Type type) {
  8293. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  8294. type.GetGenericArguments()[0] :
  8295. type;
  8296. }
  8297. }
  8298. }
  8299. //-------- Scenario 3163
  8300. namespace Scenario3163{
  8301. public class Test
  8302. {
  8303. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Func_object_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  8304. public static Expression Func_object_ArrayIndex__() {
  8305. if(Main() != 0 ) {
  8306. throw new Exception();
  8307. } else {
  8308. return Expression.Constant(0);
  8309. }
  8310. }
  8311. public static int Main()
  8312. {
  8313. Ext.StartCapture();
  8314. bool success = false;
  8315. try
  8316. {
  8317. success = check_Func_object_ArrayIndex();
  8318. }
  8319. finally
  8320. {
  8321. Ext.StopCapture();
  8322. }
  8323. return success ? 0 : 1;
  8324. }
  8325. static bool check_Func_object_ArrayIndex()
  8326. {
  8327. return checkEx_Func_object_ArrayIndex(null, -1) &
  8328. checkEx_Func_object_ArrayIndex(null, 0) &
  8329. checkEx_Func_object_ArrayIndex(null, 1) &
  8330. check_Func_object_ArrayIndex(genArrFunc_object_ArrayIndex(0)) &
  8331. check_Func_object_ArrayIndex(genArrFunc_object_ArrayIndex(1)) &
  8332. check_Func_object_ArrayIndex(genArrFunc_object_ArrayIndex(5));
  8333. }
  8334. static Func<object>[] genArrFunc_object_ArrayIndex(int size)
  8335. {
  8336. Func<object>[] vals = new Func<object>[] { null, (Func<object>)delegate() { return null; } };
  8337. Func<object>[] result = new Func<object>[size];
  8338. for (int i = 0; i < size; i++)
  8339. {
  8340. result[i] = vals[i % vals.Length];
  8341. }
  8342. return result;
  8343. }
  8344. static bool check_Func_object_ArrayIndex(Func<object>[] val)
  8345. {
  8346. bool success = checkEx_Func_object_ArrayIndex(val, -1);
  8347. for (int i = 0; i < val.Length; i++)
  8348. {
  8349. success &= check_Func_object_ArrayIndex(val, 0);
  8350. }
  8351. success &= checkEx_Func_object_ArrayIndex(val, val.Length);
  8352. return success;
  8353. }
  8354. static bool checkEx_Func_object_ArrayIndex(Func<object>[] val, int index)
  8355. {
  8356. try
  8357. {
  8358. check_Func_object_ArrayIndex(val, index);
  8359. Console.WriteLine("Func_object_ArrayIndex[" + index + "] failed");
  8360. return false;
  8361. }
  8362. catch
  8363. {
  8364. return true;
  8365. }
  8366. }
  8367. static bool check_Func_object_ArrayIndex(Func<object>[] val, int index)
  8368. {
  8369. Expression<Func<Func<object>>> e =
  8370. Expression.Lambda<Func<Func<object>>>(
  8371. Expression.ArrayIndex(Expression.Constant(val, typeof(Func<object>[])),
  8372. Expression.Constant(index, typeof(int))),
  8373. new System.Collections.Generic.List<ParameterExpression>());
  8374. Func<Func<object>> f = e.Compile();
  8375. return object.Equals(f(), val[index]);
  8376. }
  8377. }
  8378. public static class Ext {
  8379. public static void StartCapture() {
  8380. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  8381. // m.Invoke(null, new object[] { "test.dll" });
  8382. }
  8383. public static void StopCapture() {
  8384. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  8385. // m.Invoke(null, new object[0]);
  8386. }
  8387. public static bool IsIntegralOrEnum(Type type) {
  8388. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8389. case TypeCode.Byte:
  8390. case TypeCode.SByte:
  8391. case TypeCode.Int16:
  8392. case TypeCode.Int32:
  8393. case TypeCode.Int64:
  8394. case TypeCode.UInt16:
  8395. case TypeCode.UInt32:
  8396. case TypeCode.UInt64:
  8397. return true;
  8398. default:
  8399. return false;
  8400. }
  8401. }
  8402. public static bool IsFloating(Type type) {
  8403. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8404. case TypeCode.Single:
  8405. case TypeCode.Double:
  8406. return true;
  8407. default:
  8408. return false;
  8409. }
  8410. }
  8411. public static Type GetNonNullableType(Type type) {
  8412. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  8413. type.GetGenericArguments()[0] :
  8414. type;
  8415. }
  8416. }
  8417. }
  8418. //-------- Scenario 3164
  8419. namespace Scenario3164{
  8420. public class Test
  8421. {
  8422. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "IEquatable_C_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  8423. public static Expression IEquatable_C_ArrayIndex__() {
  8424. if(Main() != 0 ) {
  8425. throw new Exception();
  8426. } else {
  8427. return Expression.Constant(0);
  8428. }
  8429. }
  8430. public static int Main()
  8431. {
  8432. Ext.StartCapture();
  8433. bool success = false;
  8434. try
  8435. {
  8436. success = check_IEquatable_C_ArrayIndex();
  8437. }
  8438. finally
  8439. {
  8440. Ext.StopCapture();
  8441. }
  8442. return success ? 0 : 1;
  8443. }
  8444. static bool check_IEquatable_C_ArrayIndex()
  8445. {
  8446. return checkEx_IEquatable_C_ArrayIndex(null, -1) &
  8447. checkEx_IEquatable_C_ArrayIndex(null, 0) &
  8448. checkEx_IEquatable_C_ArrayIndex(null, 1) &
  8449. check_IEquatable_C_ArrayIndex(genArrIEquatable_C_ArrayIndex(0)) &
  8450. check_IEquatable_C_ArrayIndex(genArrIEquatable_C_ArrayIndex(1)) &
  8451. check_IEquatable_C_ArrayIndex(genArrIEquatable_C_ArrayIndex(5));
  8452. }
  8453. static IEquatable<C>[] genArrIEquatable_C_ArrayIndex(int size)
  8454. {
  8455. IEquatable<C>[] vals = new IEquatable<C>[] { null, new C(), new D(), new D(0), new D(5) };
  8456. IEquatable<C>[] result = new IEquatable<C>[size];
  8457. for (int i = 0; i < size; i++)
  8458. {
  8459. result[i] = vals[i % vals.Length];
  8460. }
  8461. return result;
  8462. }
  8463. static bool check_IEquatable_C_ArrayIndex(IEquatable<C>[] val)
  8464. {
  8465. bool success = checkEx_IEquatable_C_ArrayIndex(val, -1);
  8466. for (int i = 0; i < val.Length; i++)
  8467. {
  8468. success &= check_IEquatable_C_ArrayIndex(val, 0);
  8469. }
  8470. success &= checkEx_IEquatable_C_ArrayIndex(val, val.Length);
  8471. return success;
  8472. }
  8473. static bool checkEx_IEquatable_C_ArrayIndex(IEquatable<C>[] val, int index)
  8474. {
  8475. try
  8476. {
  8477. check_IEquatable_C_ArrayIndex(val, index);
  8478. Console.WriteLine("IEquatable_C_ArrayIndex[" + index + "] failed");
  8479. return false;
  8480. }
  8481. catch
  8482. {
  8483. return true;
  8484. }
  8485. }
  8486. static bool check_IEquatable_C_ArrayIndex(IEquatable<C>[] val, int index)
  8487. {
  8488. Expression<Func<IEquatable<C>>> e =
  8489. Expression.Lambda<Func<IEquatable<C>>>(
  8490. Expression.ArrayIndex(Expression.Constant(val, typeof(IEquatable<C>[])),
  8491. Expression.Constant(index, typeof(int))),
  8492. new System.Collections.Generic.List<ParameterExpression>());
  8493. Func<IEquatable<C>> f = e.Compile();
  8494. return object.Equals(f(), val[index]);
  8495. }
  8496. }
  8497. public static class Ext {
  8498. public static void StartCapture() {
  8499. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  8500. // m.Invoke(null, new object[] { "test.dll" });
  8501. }
  8502. public static void StopCapture() {
  8503. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  8504. // m.Invoke(null, new object[0]);
  8505. }
  8506. public static bool IsIntegralOrEnum(Type type) {
  8507. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8508. case TypeCode.Byte:
  8509. case TypeCode.SByte:
  8510. case TypeCode.Int16:
  8511. case TypeCode.Int32:
  8512. case TypeCode.Int64:
  8513. case TypeCode.UInt16:
  8514. case TypeCode.UInt32:
  8515. case TypeCode.UInt64:
  8516. return true;
  8517. default:
  8518. return false;
  8519. }
  8520. }
  8521. public static bool IsFloating(Type type) {
  8522. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8523. case TypeCode.Single:
  8524. case TypeCode.Double:
  8525. return true;
  8526. default:
  8527. return false;
  8528. }
  8529. }
  8530. public static Type GetNonNullableType(Type type) {
  8531. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  8532. type.GetGenericArguments()[0] :
  8533. type;
  8534. }
  8535. }
  8536. public interface I
  8537. {
  8538. void M();
  8539. }
  8540. public class C : IEquatable<C>, I
  8541. {
  8542. void I.M()
  8543. {
  8544. }
  8545. public override bool Equals(object o)
  8546. {
  8547. return o is C && Equals((C)o);
  8548. }
  8549. public bool Equals(C c)
  8550. {
  8551. return c != null;
  8552. }
  8553. public override int GetHashCode()
  8554. {
  8555. return 0;
  8556. }
  8557. }
  8558. public class D : C, IEquatable<D>
  8559. {
  8560. public int Val;
  8561. public D()
  8562. {
  8563. }
  8564. public D(int val)
  8565. {
  8566. Val = val;
  8567. }
  8568. public override bool Equals(object o)
  8569. {
  8570. return o is D && Equals((D)o);
  8571. }
  8572. public bool Equals(D d)
  8573. {
  8574. return d != null && d.Val == Val;
  8575. }
  8576. public override int GetHashCode()
  8577. {
  8578. return Val;
  8579. }
  8580. }
  8581. public enum E
  8582. {
  8583. A = 1, B = 2
  8584. }
  8585. public enum El : long
  8586. {
  8587. A, B, C
  8588. }
  8589. public struct S : IEquatable<S>
  8590. {
  8591. public override bool Equals(object o)
  8592. {
  8593. return (o is S) && Equals((S)o);
  8594. }
  8595. public bool Equals(S other)
  8596. {
  8597. return true;
  8598. }
  8599. public override int GetHashCode()
  8600. {
  8601. return 0;
  8602. }
  8603. }
  8604. public struct Sp : IEquatable<Sp>
  8605. {
  8606. public Sp(int i, double d)
  8607. {
  8608. I = i;
  8609. D = d;
  8610. }
  8611. public int I;
  8612. public double D;
  8613. public override bool Equals(object o)
  8614. {
  8615. return (o is Sp) && Equals((Sp)o);
  8616. }
  8617. public bool Equals(Sp other)
  8618. {
  8619. return other.I == I && other.D == D;
  8620. }
  8621. public override int GetHashCode()
  8622. {
  8623. return I.GetHashCode() ^ D.GetHashCode();
  8624. }
  8625. }
  8626. public struct Ss : IEquatable<Ss>
  8627. {
  8628. public Ss(S s)
  8629. {
  8630. Val = s;
  8631. }
  8632. public S Val;
  8633. public override bool Equals(object o)
  8634. {
  8635. return (o is Ss) && Equals((Ss)o);
  8636. }
  8637. public bool Equals(Ss other)
  8638. {
  8639. return other.Val.Equals(Val);
  8640. }
  8641. public override int GetHashCode()
  8642. {
  8643. return Val.GetHashCode();
  8644. }
  8645. }
  8646. public struct Sc : IEquatable<Sc>
  8647. {
  8648. public Sc(string s)
  8649. {
  8650. S = s;
  8651. }
  8652. public string S;
  8653. public override bool Equals(object o)
  8654. {
  8655. return (o is Sc) && Equals((Sc)o);
  8656. }
  8657. public bool Equals(Sc other)
  8658. {
  8659. return other.S == S;
  8660. }
  8661. public override int GetHashCode()
  8662. {
  8663. return S.GetHashCode();
  8664. }
  8665. }
  8666. public struct Scs : IEquatable<Scs>
  8667. {
  8668. public Scs(string s, S val)
  8669. {
  8670. S = s;
  8671. Val = val;
  8672. }
  8673. public string S;
  8674. public S Val;
  8675. public override bool Equals(object o)
  8676. {
  8677. return (o is Scs) && Equals((Scs)o);
  8678. }
  8679. public bool Equals(Scs other)
  8680. {
  8681. return other.S == S && other.Val.Equals(Val);
  8682. }
  8683. public override int GetHashCode()
  8684. {
  8685. return S.GetHashCode() ^ Val.GetHashCode();
  8686. }
  8687. }
  8688. }
  8689. //-------- Scenario 3165
  8690. namespace Scenario3165{
  8691. public class Test
  8692. {
  8693. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "IEquatable_D_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  8694. public static Expression IEquatable_D_ArrayIndex__() {
  8695. if(Main() != 0 ) {
  8696. throw new Exception();
  8697. } else {
  8698. return Expression.Constant(0);
  8699. }
  8700. }
  8701. public static int Main()
  8702. {
  8703. Ext.StartCapture();
  8704. bool success = false;
  8705. try
  8706. {
  8707. success = check_IEquatable_D_ArrayIndex();
  8708. }
  8709. finally
  8710. {
  8711. Ext.StopCapture();
  8712. }
  8713. return success ? 0 : 1;
  8714. }
  8715. static bool check_IEquatable_D_ArrayIndex()
  8716. {
  8717. return checkEx_IEquatable_D_ArrayIndex(null, -1) &
  8718. checkEx_IEquatable_D_ArrayIndex(null, 0) &
  8719. checkEx_IEquatable_D_ArrayIndex(null, 1) &
  8720. check_IEquatable_D_ArrayIndex(genArrIEquatable_D_ArrayIndex(0)) &
  8721. check_IEquatable_D_ArrayIndex(genArrIEquatable_D_ArrayIndex(1)) &
  8722. check_IEquatable_D_ArrayIndex(genArrIEquatable_D_ArrayIndex(5));
  8723. }
  8724. static IEquatable<D>[] genArrIEquatable_D_ArrayIndex(int size)
  8725. {
  8726. IEquatable<D>[] vals = new IEquatable<D>[] { null, new D(), new D(0), new D(5) };
  8727. IEquatable<D>[] result = new IEquatable<D>[size];
  8728. for (int i = 0; i < size; i++)
  8729. {
  8730. result[i] = vals[i % vals.Length];
  8731. }
  8732. return result;
  8733. }
  8734. static bool check_IEquatable_D_ArrayIndex(IEquatable<D>[] val)
  8735. {
  8736. bool success = checkEx_IEquatable_D_ArrayIndex(val, -1);
  8737. for (int i = 0; i < val.Length; i++)
  8738. {
  8739. success &= check_IEquatable_D_ArrayIndex(val, 0);
  8740. }
  8741. success &= checkEx_IEquatable_D_ArrayIndex(val, val.Length);
  8742. return success;
  8743. }
  8744. static bool checkEx_IEquatable_D_ArrayIndex(IEquatable<D>[] val, int index)
  8745. {
  8746. try
  8747. {
  8748. check_IEquatable_D_ArrayIndex(val, index);
  8749. Console.WriteLine("IEquatable_D_ArrayIndex[" + index + "] failed");
  8750. return false;
  8751. }
  8752. catch
  8753. {
  8754. return true;
  8755. }
  8756. }
  8757. static bool check_IEquatable_D_ArrayIndex(IEquatable<D>[] val, int index)
  8758. {
  8759. Expression<Func<IEquatable<D>>> e =
  8760. Expression.Lambda<Func<IEquatable<D>>>(
  8761. Expression.ArrayIndex(Expression.Constant(val, typeof(IEquatable<D>[])),
  8762. Expression.Constant(index, typeof(int))),
  8763. new System.Collections.Generic.List<ParameterExpression>());
  8764. Func<IEquatable<D>> f = e.Compile();
  8765. return object.Equals(f(), val[index]);
  8766. }
  8767. }
  8768. public static class Ext {
  8769. public static void StartCapture() {
  8770. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  8771. // m.Invoke(null, new object[] { "test.dll" });
  8772. }
  8773. public static void StopCapture() {
  8774. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  8775. // m.Invoke(null, new object[0]);
  8776. }
  8777. public static bool IsIntegralOrEnum(Type type) {
  8778. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8779. case TypeCode.Byte:
  8780. case TypeCode.SByte:
  8781. case TypeCode.Int16:
  8782. case TypeCode.Int32:
  8783. case TypeCode.Int64:
  8784. case TypeCode.UInt16:
  8785. case TypeCode.UInt32:
  8786. case TypeCode.UInt64:
  8787. return true;
  8788. default:
  8789. return false;
  8790. }
  8791. }
  8792. public static bool IsFloating(Type type) {
  8793. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  8794. case TypeCode.Single:
  8795. case TypeCode.Double:
  8796. return true;
  8797. default:
  8798. return false;
  8799. }
  8800. }
  8801. public static Type GetNonNullableType(Type type) {
  8802. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  8803. type.GetGenericArguments()[0] :
  8804. type;
  8805. }
  8806. }
  8807. public interface I
  8808. {
  8809. void M();
  8810. }
  8811. public class C : IEquatable<C>, I
  8812. {
  8813. void I.M()
  8814. {
  8815. }
  8816. public override bool Equals(object o)
  8817. {
  8818. return o is C && Equals((C)o);
  8819. }
  8820. public bool Equals(C c)
  8821. {
  8822. return c != null;
  8823. }
  8824. public override int GetHashCode()
  8825. {
  8826. return 0;
  8827. }
  8828. }
  8829. public class D : C, IEquatable<D>
  8830. {
  8831. public int Val;
  8832. public D()
  8833. {
  8834. }
  8835. public D(int val)
  8836. {
  8837. Val = val;
  8838. }
  8839. public override bool Equals(object o)
  8840. {
  8841. return o is D && Equals((D)o);
  8842. }
  8843. public bool Equals(D d)
  8844. {
  8845. return d != null && d.Val == Val;
  8846. }
  8847. public override int GetHashCode()
  8848. {
  8849. return Val;
  8850. }
  8851. }
  8852. public enum E
  8853. {
  8854. A = 1, B = 2
  8855. }
  8856. public enum El : long
  8857. {
  8858. A, B, C
  8859. }
  8860. public struct S : IEquatable<S>
  8861. {
  8862. public override bool Equals(object o)
  8863. {
  8864. return (o is S) && Equals((S)o);
  8865. }
  8866. public bool Equals(S other)
  8867. {
  8868. return true;
  8869. }
  8870. public override int GetHashCode()
  8871. {
  8872. return 0;
  8873. }
  8874. }
  8875. public struct Sp : IEquatable<Sp>
  8876. {
  8877. public Sp(int i, double d)
  8878. {
  8879. I = i;
  8880. D = d;
  8881. }
  8882. public int I;
  8883. public double D;
  8884. public override bool Equals(object o)
  8885. {
  8886. return (o is Sp) && Equals((Sp)o);
  8887. }
  8888. public bool Equals(Sp other)
  8889. {
  8890. return other.I == I && other.D == D;
  8891. }
  8892. public override int GetHashCode()
  8893. {
  8894. return I.GetHashCode() ^ D.GetHashCode();
  8895. }
  8896. }
  8897. public struct Ss : IEquatable<Ss>
  8898. {
  8899. public Ss(S s)
  8900. {
  8901. Val = s;
  8902. }
  8903. public S Val;
  8904. public override bool Equals(object o)
  8905. {
  8906. return (o is Ss) && Equals((Ss)o);
  8907. }
  8908. public bool Equals(Ss other)
  8909. {
  8910. return other.Val.Equals(Val);
  8911. }
  8912. public override int GetHashCode()
  8913. {
  8914. return Val.GetHashCode();
  8915. }
  8916. }
  8917. public struct Sc : IEquatable<Sc>
  8918. {
  8919. public Sc(string s)
  8920. {
  8921. S = s;
  8922. }
  8923. public string S;
  8924. public override bool Equals(object o)
  8925. {
  8926. return (o is Sc) && Equals((Sc)o);
  8927. }
  8928. public bool Equals(Sc other)
  8929. {
  8930. return other.S == S;
  8931. }
  8932. public override int GetHashCode()
  8933. {
  8934. return S.GetHashCode();
  8935. }
  8936. }
  8937. public struct Scs : IEquatable<Scs>
  8938. {
  8939. public Scs(string s, S val)
  8940. {
  8941. S = s;
  8942. Val = val;
  8943. }
  8944. public string S;
  8945. public S Val;
  8946. public override bool Equals(object o)
  8947. {
  8948. return (o is Scs) && Equals((Scs)o);
  8949. }
  8950. public bool Equals(Scs other)
  8951. {
  8952. return other.S == S && other.Val.Equals(Val);
  8953. }
  8954. public override int GetHashCode()
  8955. {
  8956. return S.GetHashCode() ^ Val.GetHashCode();
  8957. }
  8958. }
  8959. }
  8960. //-------- Scenario 3166
  8961. namespace Scenario3166{
  8962. public class Test
  8963. {
  8964. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "I_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  8965. public static Expression I_ArrayIndex__() {
  8966. if(Main() != 0 ) {
  8967. throw new Exception();
  8968. } else {
  8969. return Expression.Constant(0);
  8970. }
  8971. }
  8972. public static int Main()
  8973. {
  8974. Ext.StartCapture();
  8975. bool success = false;
  8976. try
  8977. {
  8978. success = check_I_ArrayIndex();
  8979. }
  8980. finally
  8981. {
  8982. Ext.StopCapture();
  8983. }
  8984. return success ? 0 : 1;
  8985. }
  8986. static bool check_I_ArrayIndex()
  8987. {
  8988. return checkEx_I_ArrayIndex(null, -1) &
  8989. checkEx_I_ArrayIndex(null, 0) &
  8990. checkEx_I_ArrayIndex(null, 1) &
  8991. check_I_ArrayIndex(genArrI_ArrayIndex(0)) &
  8992. check_I_ArrayIndex(genArrI_ArrayIndex(1)) &
  8993. check_I_ArrayIndex(genArrI_ArrayIndex(5));
  8994. }
  8995. static I[] genArrI_ArrayIndex(int size)
  8996. {
  8997. I[] vals = new I[] { null, new C(), new D(), new D(0), new D(5) };
  8998. I[] result = new I[size];
  8999. for (int i = 0; i < size; i++)
  9000. {
  9001. result[i] = vals[i % vals.Length];
  9002. }
  9003. return result;
  9004. }
  9005. static bool check_I_ArrayIndex(I[] val)
  9006. {
  9007. bool success = checkEx_I_ArrayIndex(val, -1);
  9008. for (int i = 0; i < val.Length; i++)
  9009. {
  9010. success &= check_I_ArrayIndex(val, 0);
  9011. }
  9012. success &= checkEx_I_ArrayIndex(val, val.Length);
  9013. return success;
  9014. }
  9015. static bool checkEx_I_ArrayIndex(I[] val, int index)
  9016. {
  9017. try
  9018. {
  9019. check_I_ArrayIndex(val, index);
  9020. Console.WriteLine("I_ArrayIndex[" + index + "] failed");
  9021. return false;
  9022. }
  9023. catch
  9024. {
  9025. return true;
  9026. }
  9027. }
  9028. static bool check_I_ArrayIndex(I[] val, int index)
  9029. {
  9030. Expression<Func<I>> e =
  9031. Expression.Lambda<Func<I>>(
  9032. Expression.ArrayIndex(Expression.Constant(val, typeof(I[])),
  9033. Expression.Constant(index, typeof(int))),
  9034. new System.Collections.Generic.List<ParameterExpression>());
  9035. Func<I> f = e.Compile();
  9036. return object.Equals(f(), val[index]);
  9037. }
  9038. }
  9039. public static class Ext {
  9040. public static void StartCapture() {
  9041. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  9042. // m.Invoke(null, new object[] { "test.dll" });
  9043. }
  9044. public static void StopCapture() {
  9045. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  9046. // m.Invoke(null, new object[0]);
  9047. }
  9048. public static bool IsIntegralOrEnum(Type type) {
  9049. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  9050. case TypeCode.Byte:
  9051. case TypeCode.SByte:
  9052. case TypeCode.Int16:
  9053. case TypeCode.Int32:
  9054. case TypeCode.Int64:
  9055. case TypeCode.UInt16:
  9056. case TypeCode.UInt32:
  9057. case TypeCode.UInt64:
  9058. return true;
  9059. default:
  9060. return false;
  9061. }
  9062. }
  9063. public static bool IsFloating(Type type) {
  9064. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  9065. case TypeCode.Single:
  9066. case TypeCode.Double:
  9067. return true;
  9068. default:
  9069. return false;
  9070. }
  9071. }
  9072. public static Type GetNonNullableType(Type type) {
  9073. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  9074. type.GetGenericArguments()[0] :
  9075. type;
  9076. }
  9077. }
  9078. public interface I
  9079. {
  9080. void M();
  9081. }
  9082. public class C : IEquatable<C>, I
  9083. {
  9084. void I.M()
  9085. {
  9086. }
  9087. public override bool Equals(object o)
  9088. {
  9089. return o is C && Equals((C)o);
  9090. }
  9091. public bool Equals(C c)
  9092. {
  9093. return c != null;
  9094. }
  9095. public override int GetHashCode()
  9096. {
  9097. return 0;
  9098. }
  9099. }
  9100. public class D : C, IEquatable<D>
  9101. {
  9102. public int Val;
  9103. public D()
  9104. {
  9105. }
  9106. public D(int val)
  9107. {
  9108. Val = val;
  9109. }
  9110. public override bool Equals(object o)
  9111. {
  9112. return o is D && Equals((D)o);
  9113. }
  9114. public bool Equals(D d)
  9115. {
  9116. return d != null && d.Val == Val;
  9117. }
  9118. public override int GetHashCode()
  9119. {
  9120. return Val;
  9121. }
  9122. }
  9123. public enum E
  9124. {
  9125. A = 1, B = 2
  9126. }
  9127. public enum El : long
  9128. {
  9129. A, B, C
  9130. }
  9131. public struct S : IEquatable<S>
  9132. {
  9133. public override bool Equals(object o)
  9134. {
  9135. return (o is S) && Equals((S)o);
  9136. }
  9137. public bool Equals(S other)
  9138. {
  9139. return true;
  9140. }
  9141. public override int GetHashCode()
  9142. {
  9143. return 0;
  9144. }
  9145. }
  9146. public struct Sp : IEquatable<Sp>
  9147. {
  9148. public Sp(int i, double d)
  9149. {
  9150. I = i;
  9151. D = d;
  9152. }
  9153. public int I;
  9154. public double D;
  9155. public override bool Equals(object o)
  9156. {
  9157. return (o is Sp) && Equals((Sp)o);
  9158. }
  9159. public bool Equals(Sp other)
  9160. {
  9161. return other.I == I && other.D == D;
  9162. }
  9163. public override int GetHashCode()
  9164. {
  9165. return I.GetHashCode() ^ D.GetHashCode();
  9166. }
  9167. }
  9168. public struct Ss : IEquatable<Ss>
  9169. {
  9170. public Ss(S s)
  9171. {
  9172. Val = s;
  9173. }
  9174. public S Val;
  9175. public override bool Equals(object o)
  9176. {
  9177. return (o is Ss) && Equals((Ss)o);
  9178. }
  9179. public bool Equals(Ss other)
  9180. {
  9181. return other.Val.Equals(Val);
  9182. }
  9183. public override int GetHashCode()
  9184. {
  9185. return Val.GetHashCode();
  9186. }
  9187. }
  9188. public struct Sc : IEquatable<Sc>
  9189. {
  9190. public Sc(string s)
  9191. {
  9192. S = s;
  9193. }
  9194. public string S;
  9195. public override bool Equals(object o)
  9196. {
  9197. return (o is Sc) && Equals((Sc)o);
  9198. }
  9199. public bool Equals(Sc other)
  9200. {
  9201. return other.S == S;
  9202. }
  9203. public override int GetHashCode()
  9204. {
  9205. return S.GetHashCode();
  9206. }
  9207. }
  9208. public struct Scs : IEquatable<Scs>
  9209. {
  9210. public Scs(string s, S val)
  9211. {
  9212. S = s;
  9213. Val = val;
  9214. }
  9215. public string S;
  9216. public S Val;
  9217. public override bool Equals(object o)
  9218. {
  9219. return (o is Scs) && Equals((Scs)o);
  9220. }
  9221. public bool Equals(Scs other)
  9222. {
  9223. return other.S == S && other.Val.Equals(Val);
  9224. }
  9225. public override int GetHashCode()
  9226. {
  9227. return S.GetHashCode() ^ Val.GetHashCode();
  9228. }
  9229. }
  9230. }
  9231. }