PageRenderTime 62ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 4321 lines | 3565 code | 641 blank | 115 comment | 377 complexity | 473d095d9e7b75504fb7dc0c0b47302e 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 3167
  11. namespace Scenario3167{
  12. public class Test
  13. {
  14. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "byteq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  15. public static Expression byteq_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_byteq_ArrayIndex();
  29. }
  30. finally
  31. {
  32. Ext.StopCapture();
  33. }
  34. return success ? 0 : 1;
  35. }
  36. static bool check_byteq_ArrayIndex() {
  37. return checkEx_byteq_ArrayIndex(null, -1) &
  38. checkEx_byteq_ArrayIndex(null, 0) &
  39. checkEx_byteq_ArrayIndex(null, 1) &
  40. check_byteq_ArrayIndex(genArrbyteq_ArrayIndex(0)) &
  41. check_byteq_ArrayIndex(genArrbyteq_ArrayIndex(1)) &
  42. check_byteq_ArrayIndex(genArrbyteq_ArrayIndex(5));
  43. }
  44. static byte?[] genArrbyteq_ArrayIndex(int size) {
  45. byte?[] vals = new byte?[] { 0, 1, byte.MaxValue };
  46. byte?[] result = new byte?[size];
  47. for (int i = 0; i < size; i++) {
  48. result[i] = vals[i % vals.Length];
  49. }
  50. return result;
  51. }
  52. static bool check_byteq_ArrayIndex(byte?[] val) {
  53. bool success = checkEx_byteq_ArrayIndex(val, -1);
  54. for (int i = 0; i < val.Length; i++) {
  55. success &= check_byteq_ArrayIndex(val, 0);
  56. }
  57. success &= checkEx_byteq_ArrayIndex(val, val.Length);
  58. return success;
  59. }
  60. static bool checkEx_byteq_ArrayIndex(byte?[] val, int index) {
  61. try {
  62. check_byteq_ArrayIndex(val, index);
  63. Console.WriteLine("byteq_ArrayIndex[" + index + "] failed");
  64. return false;
  65. }
  66. catch {
  67. return true;
  68. }
  69. }
  70. static bool check_byteq_ArrayIndex(byte?[] val, int index) {
  71. Expression<Func<byte?>> e =
  72. Expression.Lambda<Func<byte?>>(
  73. Expression.ArrayIndex(Expression.Constant(val, typeof(byte?[])),
  74. Expression.Constant(index, typeof(int))),
  75. new System.Collections.Generic.List<ParameterExpression>());
  76. Func<byte?> f = e.Compile();
  77. return object.Equals(f(), val[index]);
  78. }
  79. }
  80. public static class Ext {
  81. public static void StartCapture() {
  82. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  83. // m.Invoke(null, new object[] { "test.dll" });
  84. }
  85. public static void StopCapture() {
  86. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  87. // m.Invoke(null, new object[0]);
  88. }
  89. public static bool IsIntegralOrEnum(Type type) {
  90. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  91. case TypeCode.Byte:
  92. case TypeCode.SByte:
  93. case TypeCode.Int16:
  94. case TypeCode.Int32:
  95. case TypeCode.Int64:
  96. case TypeCode.UInt16:
  97. case TypeCode.UInt32:
  98. case TypeCode.UInt64:
  99. return true;
  100. default:
  101. return false;
  102. }
  103. }
  104. public static bool IsFloating(Type type) {
  105. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  106. case TypeCode.Single:
  107. case TypeCode.Double:
  108. return true;
  109. default:
  110. return false;
  111. }
  112. }
  113. public static Type GetNonNullableType(Type type) {
  114. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  115. type.GetGenericArguments()[0] :
  116. type;
  117. }
  118. }
  119. }
  120. //-------- Scenario 3168
  121. namespace Scenario3168{
  122. public class Test
  123. {
  124. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "ushortq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  125. public static Expression ushortq_ArrayIndex__() {
  126. if(Main() != 0 ) {
  127. throw new Exception();
  128. } else {
  129. return Expression.Constant(0);
  130. }
  131. }
  132. public static int Main()
  133. {
  134. Ext.StartCapture();
  135. bool success = false;
  136. try
  137. {
  138. success = check_ushortq_ArrayIndex();
  139. }
  140. finally
  141. {
  142. Ext.StopCapture();
  143. }
  144. return success ? 0 : 1;
  145. }
  146. static bool check_ushortq_ArrayIndex() {
  147. return checkEx_ushortq_ArrayIndex(null, -1) &
  148. checkEx_ushortq_ArrayIndex(null, 0) &
  149. checkEx_ushortq_ArrayIndex(null, 1) &
  150. check_ushortq_ArrayIndex(genArrushortq_ArrayIndex(0)) &
  151. check_ushortq_ArrayIndex(genArrushortq_ArrayIndex(1)) &
  152. check_ushortq_ArrayIndex(genArrushortq_ArrayIndex(5));
  153. }
  154. static ushort?[] genArrushortq_ArrayIndex(int size) {
  155. ushort?[] vals = new ushort?[] { 0, 1, ushort.MaxValue };
  156. ushort?[] result = new ushort?[size];
  157. for (int i = 0; i < size; i++) {
  158. result[i] = vals[i % vals.Length];
  159. }
  160. return result;
  161. }
  162. static bool check_ushortq_ArrayIndex(ushort?[] val) {
  163. bool success = checkEx_ushortq_ArrayIndex(val, -1);
  164. for (int i = 0; i < val.Length; i++) {
  165. success &= check_ushortq_ArrayIndex(val, 0);
  166. }
  167. success &= checkEx_ushortq_ArrayIndex(val, val.Length);
  168. return success;
  169. }
  170. static bool checkEx_ushortq_ArrayIndex(ushort?[] val, int index) {
  171. try {
  172. check_ushortq_ArrayIndex(val, index);
  173. Console.WriteLine("ushortq_ArrayIndex[" + index + "] failed");
  174. return false;
  175. }
  176. catch {
  177. return true;
  178. }
  179. }
  180. static bool check_ushortq_ArrayIndex(ushort?[] val, int index) {
  181. Expression<Func<ushort?>> e =
  182. Expression.Lambda<Func<ushort?>>(
  183. Expression.ArrayIndex(Expression.Constant(val, typeof(ushort?[])),
  184. Expression.Constant(index, typeof(int))),
  185. new System.Collections.Generic.List<ParameterExpression>());
  186. Func<ushort?> f = e.Compile();
  187. return object.Equals(f(), val[index]);
  188. }
  189. }
  190. public static class Ext {
  191. public static void StartCapture() {
  192. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  193. // m.Invoke(null, new object[] { "test.dll" });
  194. }
  195. public static void StopCapture() {
  196. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  197. // m.Invoke(null, new object[0]);
  198. }
  199. public static bool IsIntegralOrEnum(Type type) {
  200. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  201. case TypeCode.Byte:
  202. case TypeCode.SByte:
  203. case TypeCode.Int16:
  204. case TypeCode.Int32:
  205. case TypeCode.Int64:
  206. case TypeCode.UInt16:
  207. case TypeCode.UInt32:
  208. case TypeCode.UInt64:
  209. return true;
  210. default:
  211. return false;
  212. }
  213. }
  214. public static bool IsFloating(Type type) {
  215. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  216. case TypeCode.Single:
  217. case TypeCode.Double:
  218. return true;
  219. default:
  220. return false;
  221. }
  222. }
  223. public static Type GetNonNullableType(Type type) {
  224. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  225. type.GetGenericArguments()[0] :
  226. type;
  227. }
  228. }
  229. }
  230. //-------- Scenario 3169
  231. namespace Scenario3169{
  232. public class Test
  233. {
  234. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "uintq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  235. public static Expression uintq_ArrayIndex__() {
  236. if(Main() != 0 ) {
  237. throw new Exception();
  238. } else {
  239. return Expression.Constant(0);
  240. }
  241. }
  242. public static int Main()
  243. {
  244. Ext.StartCapture();
  245. bool success = false;
  246. try
  247. {
  248. success = check_uintq_ArrayIndex();
  249. }
  250. finally
  251. {
  252. Ext.StopCapture();
  253. }
  254. return success ? 0 : 1;
  255. }
  256. static bool check_uintq_ArrayIndex() {
  257. return checkEx_uintq_ArrayIndex(null, -1) &
  258. checkEx_uintq_ArrayIndex(null, 0) &
  259. checkEx_uintq_ArrayIndex(null, 1) &
  260. check_uintq_ArrayIndex(genArruintq_ArrayIndex(0)) &
  261. check_uintq_ArrayIndex(genArruintq_ArrayIndex(1)) &
  262. check_uintq_ArrayIndex(genArruintq_ArrayIndex(5));
  263. }
  264. static uint?[] genArruintq_ArrayIndex(int size) {
  265. uint?[] vals = new uint?[] { 0, 1, uint.MaxValue };
  266. uint?[] result = new uint?[size];
  267. for (int i = 0; i < size; i++) {
  268. result[i] = vals[i % vals.Length];
  269. }
  270. return result;
  271. }
  272. static bool check_uintq_ArrayIndex(uint?[] val) {
  273. bool success = checkEx_uintq_ArrayIndex(val, -1);
  274. for (int i = 0; i < val.Length; i++) {
  275. success &= check_uintq_ArrayIndex(val, 0);
  276. }
  277. success &= checkEx_uintq_ArrayIndex(val, val.Length);
  278. return success;
  279. }
  280. static bool checkEx_uintq_ArrayIndex(uint?[] val, int index) {
  281. try {
  282. check_uintq_ArrayIndex(val, index);
  283. Console.WriteLine("uintq_ArrayIndex[" + index + "] failed");
  284. return false;
  285. }
  286. catch {
  287. return true;
  288. }
  289. }
  290. static bool check_uintq_ArrayIndex(uint?[] val, int index) {
  291. Expression<Func<uint?>> e =
  292. Expression.Lambda<Func<uint?>>(
  293. Expression.ArrayIndex(Expression.Constant(val, typeof(uint?[])),
  294. Expression.Constant(index, typeof(int))),
  295. new System.Collections.Generic.List<ParameterExpression>());
  296. Func<uint?> f = e.Compile();
  297. return object.Equals(f(), val[index]);
  298. }
  299. }
  300. public static class Ext {
  301. public static void StartCapture() {
  302. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  303. // m.Invoke(null, new object[] { "test.dll" });
  304. }
  305. public static void StopCapture() {
  306. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  307. // m.Invoke(null, new object[0]);
  308. }
  309. public static bool IsIntegralOrEnum(Type type) {
  310. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  311. case TypeCode.Byte:
  312. case TypeCode.SByte:
  313. case TypeCode.Int16:
  314. case TypeCode.Int32:
  315. case TypeCode.Int64:
  316. case TypeCode.UInt16:
  317. case TypeCode.UInt32:
  318. case TypeCode.UInt64:
  319. return true;
  320. default:
  321. return false;
  322. }
  323. }
  324. public static bool IsFloating(Type type) {
  325. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  326. case TypeCode.Single:
  327. case TypeCode.Double:
  328. return true;
  329. default:
  330. return false;
  331. }
  332. }
  333. public static Type GetNonNullableType(Type type) {
  334. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  335. type.GetGenericArguments()[0] :
  336. type;
  337. }
  338. }
  339. }
  340. //-------- Scenario 3170
  341. namespace Scenario3170{
  342. public class Test
  343. {
  344. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "ulongq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  345. public static Expression ulongq_ArrayIndex__() {
  346. if(Main() != 0 ) {
  347. throw new Exception();
  348. } else {
  349. return Expression.Constant(0);
  350. }
  351. }
  352. public static int Main()
  353. {
  354. Ext.StartCapture();
  355. bool success = false;
  356. try
  357. {
  358. success = check_ulongq_ArrayIndex();
  359. }
  360. finally
  361. {
  362. Ext.StopCapture();
  363. }
  364. return success ? 0 : 1;
  365. }
  366. static bool check_ulongq_ArrayIndex() {
  367. return checkEx_ulongq_ArrayIndex(null, -1) &
  368. checkEx_ulongq_ArrayIndex(null, 0) &
  369. checkEx_ulongq_ArrayIndex(null, 1) &
  370. check_ulongq_ArrayIndex(genArrulongq_ArrayIndex(0)) &
  371. check_ulongq_ArrayIndex(genArrulongq_ArrayIndex(1)) &
  372. check_ulongq_ArrayIndex(genArrulongq_ArrayIndex(5));
  373. }
  374. static ulong?[] genArrulongq_ArrayIndex(int size) {
  375. ulong?[] vals = new ulong?[] { 0, 1, ulong.MaxValue };
  376. ulong?[] result = new ulong?[size];
  377. for (int i = 0; i < size; i++) {
  378. result[i] = vals[i % vals.Length];
  379. }
  380. return result;
  381. }
  382. static bool check_ulongq_ArrayIndex(ulong?[] val) {
  383. bool success = checkEx_ulongq_ArrayIndex(val, -1);
  384. for (int i = 0; i < val.Length; i++) {
  385. success &= check_ulongq_ArrayIndex(val, 0);
  386. }
  387. success &= checkEx_ulongq_ArrayIndex(val, val.Length);
  388. return success;
  389. }
  390. static bool checkEx_ulongq_ArrayIndex(ulong?[] val, int index) {
  391. try {
  392. check_ulongq_ArrayIndex(val, index);
  393. Console.WriteLine("ulongq_ArrayIndex[" + index + "] failed");
  394. return false;
  395. }
  396. catch {
  397. return true;
  398. }
  399. }
  400. static bool check_ulongq_ArrayIndex(ulong?[] val, int index) {
  401. Expression<Func<ulong?>> e =
  402. Expression.Lambda<Func<ulong?>>(
  403. Expression.ArrayIndex(Expression.Constant(val, typeof(ulong?[])),
  404. Expression.Constant(index, typeof(int))),
  405. new System.Collections.Generic.List<ParameterExpression>());
  406. Func<ulong?> f = e.Compile();
  407. return object.Equals(f(), val[index]);
  408. }
  409. }
  410. public static class Ext {
  411. public static void StartCapture() {
  412. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  413. // m.Invoke(null, new object[] { "test.dll" });
  414. }
  415. public static void StopCapture() {
  416. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  417. // m.Invoke(null, new object[0]);
  418. }
  419. public static bool IsIntegralOrEnum(Type type) {
  420. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  421. case TypeCode.Byte:
  422. case TypeCode.SByte:
  423. case TypeCode.Int16:
  424. case TypeCode.Int32:
  425. case TypeCode.Int64:
  426. case TypeCode.UInt16:
  427. case TypeCode.UInt32:
  428. case TypeCode.UInt64:
  429. return true;
  430. default:
  431. return false;
  432. }
  433. }
  434. public static bool IsFloating(Type type) {
  435. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  436. case TypeCode.Single:
  437. case TypeCode.Double:
  438. return true;
  439. default:
  440. return false;
  441. }
  442. }
  443. public static Type GetNonNullableType(Type type) {
  444. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  445. type.GetGenericArguments()[0] :
  446. type;
  447. }
  448. }
  449. }
  450. //-------- Scenario 3171
  451. namespace Scenario3171{
  452. public class Test
  453. {
  454. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "sbyteq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  455. public static Expression sbyteq_ArrayIndex__() {
  456. if(Main() != 0 ) {
  457. throw new Exception();
  458. } else {
  459. return Expression.Constant(0);
  460. }
  461. }
  462. public static int Main()
  463. {
  464. Ext.StartCapture();
  465. bool success = false;
  466. try
  467. {
  468. success = check_sbyteq_ArrayIndex();
  469. }
  470. finally
  471. {
  472. Ext.StopCapture();
  473. }
  474. return success ? 0 : 1;
  475. }
  476. static bool check_sbyteq_ArrayIndex() {
  477. return checkEx_sbyteq_ArrayIndex(null, -1) &
  478. checkEx_sbyteq_ArrayIndex(null, 0) &
  479. checkEx_sbyteq_ArrayIndex(null, 1) &
  480. check_sbyteq_ArrayIndex(genArrsbyteq_ArrayIndex(0)) &
  481. check_sbyteq_ArrayIndex(genArrsbyteq_ArrayIndex(1)) &
  482. check_sbyteq_ArrayIndex(genArrsbyteq_ArrayIndex(5));
  483. }
  484. static sbyte?[] genArrsbyteq_ArrayIndex(int size) {
  485. sbyte?[] vals = new sbyte?[] { 0, 1, -1, sbyte.MinValue, sbyte.MaxValue };
  486. sbyte?[] result = new sbyte?[size];
  487. for (int i = 0; i < size; i++) {
  488. result[i] = vals[i % vals.Length];
  489. }
  490. return result;
  491. }
  492. static bool check_sbyteq_ArrayIndex(sbyte?[] val) {
  493. bool success = checkEx_sbyteq_ArrayIndex(val, -1);
  494. for (int i = 0; i < val.Length; i++) {
  495. success &= check_sbyteq_ArrayIndex(val, 0);
  496. }
  497. success &= checkEx_sbyteq_ArrayIndex(val, val.Length);
  498. return success;
  499. }
  500. static bool checkEx_sbyteq_ArrayIndex(sbyte?[] val, int index) {
  501. try {
  502. check_sbyteq_ArrayIndex(val, index);
  503. Console.WriteLine("sbyteq_ArrayIndex[" + index + "] failed");
  504. return false;
  505. }
  506. catch {
  507. return true;
  508. }
  509. }
  510. static bool check_sbyteq_ArrayIndex(sbyte?[] val, int index) {
  511. Expression<Func<sbyte?>> e =
  512. Expression.Lambda<Func<sbyte?>>(
  513. Expression.ArrayIndex(Expression.Constant(val, typeof(sbyte?[])),
  514. Expression.Constant(index, typeof(int))),
  515. new System.Collections.Generic.List<ParameterExpression>());
  516. Func<sbyte?> f = e.Compile();
  517. return object.Equals(f(), val[index]);
  518. }
  519. }
  520. public static class Ext {
  521. public static void StartCapture() {
  522. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  523. // m.Invoke(null, new object[] { "test.dll" });
  524. }
  525. public static void StopCapture() {
  526. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  527. // m.Invoke(null, new object[0]);
  528. }
  529. public static bool IsIntegralOrEnum(Type type) {
  530. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  531. case TypeCode.Byte:
  532. case TypeCode.SByte:
  533. case TypeCode.Int16:
  534. case TypeCode.Int32:
  535. case TypeCode.Int64:
  536. case TypeCode.UInt16:
  537. case TypeCode.UInt32:
  538. case TypeCode.UInt64:
  539. return true;
  540. default:
  541. return false;
  542. }
  543. }
  544. public static bool IsFloating(Type type) {
  545. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  546. case TypeCode.Single:
  547. case TypeCode.Double:
  548. return true;
  549. default:
  550. return false;
  551. }
  552. }
  553. public static Type GetNonNullableType(Type type) {
  554. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  555. type.GetGenericArguments()[0] :
  556. type;
  557. }
  558. }
  559. }
  560. //-------- Scenario 3172
  561. namespace Scenario3172{
  562. public class Test
  563. {
  564. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "shortq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  565. public static Expression shortq_ArrayIndex__() {
  566. if(Main() != 0 ) {
  567. throw new Exception();
  568. } else {
  569. return Expression.Constant(0);
  570. }
  571. }
  572. public static int Main()
  573. {
  574. Ext.StartCapture();
  575. bool success = false;
  576. try
  577. {
  578. success = check_shortq_ArrayIndex();
  579. }
  580. finally
  581. {
  582. Ext.StopCapture();
  583. }
  584. return success ? 0 : 1;
  585. }
  586. static bool check_shortq_ArrayIndex() {
  587. return checkEx_shortq_ArrayIndex(null, -1) &
  588. checkEx_shortq_ArrayIndex(null, 0) &
  589. checkEx_shortq_ArrayIndex(null, 1) &
  590. check_shortq_ArrayIndex(genArrshortq_ArrayIndex(0)) &
  591. check_shortq_ArrayIndex(genArrshortq_ArrayIndex(1)) &
  592. check_shortq_ArrayIndex(genArrshortq_ArrayIndex(5));
  593. }
  594. static short?[] genArrshortq_ArrayIndex(int size) {
  595. short?[] vals = new short?[] { 0, 1, -1, short.MinValue, short.MaxValue };
  596. short?[] result = new short?[size];
  597. for (int i = 0; i < size; i++) {
  598. result[i] = vals[i % vals.Length];
  599. }
  600. return result;
  601. }
  602. static bool check_shortq_ArrayIndex(short?[] val) {
  603. bool success = checkEx_shortq_ArrayIndex(val, -1);
  604. for (int i = 0; i < val.Length; i++) {
  605. success &= check_shortq_ArrayIndex(val, 0);
  606. }
  607. success &= checkEx_shortq_ArrayIndex(val, val.Length);
  608. return success;
  609. }
  610. static bool checkEx_shortq_ArrayIndex(short?[] val, int index) {
  611. try {
  612. check_shortq_ArrayIndex(val, index);
  613. Console.WriteLine("shortq_ArrayIndex[" + index + "] failed");
  614. return false;
  615. }
  616. catch {
  617. return true;
  618. }
  619. }
  620. static bool check_shortq_ArrayIndex(short?[] val, int index) {
  621. Expression<Func<short?>> e =
  622. Expression.Lambda<Func<short?>>(
  623. Expression.ArrayIndex(Expression.Constant(val, typeof(short?[])),
  624. Expression.Constant(index, typeof(int))),
  625. new System.Collections.Generic.List<ParameterExpression>());
  626. Func<short?> f = e.Compile();
  627. return object.Equals(f(), val[index]);
  628. }
  629. }
  630. public static class Ext {
  631. public static void StartCapture() {
  632. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  633. // m.Invoke(null, new object[] { "test.dll" });
  634. }
  635. public static void StopCapture() {
  636. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  637. // m.Invoke(null, new object[0]);
  638. }
  639. public static bool IsIntegralOrEnum(Type type) {
  640. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  641. case TypeCode.Byte:
  642. case TypeCode.SByte:
  643. case TypeCode.Int16:
  644. case TypeCode.Int32:
  645. case TypeCode.Int64:
  646. case TypeCode.UInt16:
  647. case TypeCode.UInt32:
  648. case TypeCode.UInt64:
  649. return true;
  650. default:
  651. return false;
  652. }
  653. }
  654. public static bool IsFloating(Type type) {
  655. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  656. case TypeCode.Single:
  657. case TypeCode.Double:
  658. return true;
  659. default:
  660. return false;
  661. }
  662. }
  663. public static Type GetNonNullableType(Type type) {
  664. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  665. type.GetGenericArguments()[0] :
  666. type;
  667. }
  668. }
  669. }
  670. //-------- Scenario 3173
  671. namespace Scenario3173{
  672. public class Test
  673. {
  674. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "intq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  675. public static Expression intq_ArrayIndex__() {
  676. if(Main() != 0 ) {
  677. throw new Exception();
  678. } else {
  679. return Expression.Constant(0);
  680. }
  681. }
  682. public static int Main()
  683. {
  684. Ext.StartCapture();
  685. bool success = false;
  686. try
  687. {
  688. success = check_intq_ArrayIndex();
  689. }
  690. finally
  691. {
  692. Ext.StopCapture();
  693. }
  694. return success ? 0 : 1;
  695. }
  696. static bool check_intq_ArrayIndex() {
  697. return checkEx_intq_ArrayIndex(null, -1) &
  698. checkEx_intq_ArrayIndex(null, 0) &
  699. checkEx_intq_ArrayIndex(null, 1) &
  700. check_intq_ArrayIndex(genArrintq_ArrayIndex(0)) &
  701. check_intq_ArrayIndex(genArrintq_ArrayIndex(1)) &
  702. check_intq_ArrayIndex(genArrintq_ArrayIndex(5));
  703. }
  704. static int?[] genArrintq_ArrayIndex(int size) {
  705. int?[] vals = new int?[] { 0, 1, -1, int.MinValue, int.MaxValue };
  706. int?[] result = new int?[size];
  707. for (int i = 0; i < size; i++) {
  708. result[i] = vals[i % vals.Length];
  709. }
  710. return result;
  711. }
  712. static bool check_intq_ArrayIndex(int?[] val) {
  713. bool success = checkEx_intq_ArrayIndex(val, -1);
  714. for (int i = 0; i < val.Length; i++) {
  715. success &= check_intq_ArrayIndex(val, 0);
  716. }
  717. success &= checkEx_intq_ArrayIndex(val, val.Length);
  718. return success;
  719. }
  720. static bool checkEx_intq_ArrayIndex(int?[] val, int index) {
  721. try {
  722. check_intq_ArrayIndex(val, index);
  723. Console.WriteLine("intq_ArrayIndex[" + index + "] failed");
  724. return false;
  725. }
  726. catch {
  727. return true;
  728. }
  729. }
  730. static bool check_intq_ArrayIndex(int?[] val, int index) {
  731. Expression<Func<int?>> e =
  732. Expression.Lambda<Func<int?>>(
  733. Expression.ArrayIndex(Expression.Constant(val, typeof(int?[])),
  734. Expression.Constant(index, typeof(int))),
  735. new System.Collections.Generic.List<ParameterExpression>());
  736. Func<int?> f = e.Compile();
  737. return object.Equals(f(), val[index]);
  738. }
  739. }
  740. public static class Ext {
  741. public static void StartCapture() {
  742. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  743. // m.Invoke(null, new object[] { "test.dll" });
  744. }
  745. public static void StopCapture() {
  746. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  747. // m.Invoke(null, new object[0]);
  748. }
  749. public static bool IsIntegralOrEnum(Type type) {
  750. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  751. case TypeCode.Byte:
  752. case TypeCode.SByte:
  753. case TypeCode.Int16:
  754. case TypeCode.Int32:
  755. case TypeCode.Int64:
  756. case TypeCode.UInt16:
  757. case TypeCode.UInt32:
  758. case TypeCode.UInt64:
  759. return true;
  760. default:
  761. return false;
  762. }
  763. }
  764. public static bool IsFloating(Type type) {
  765. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  766. case TypeCode.Single:
  767. case TypeCode.Double:
  768. return true;
  769. default:
  770. return false;
  771. }
  772. }
  773. public static Type GetNonNullableType(Type type) {
  774. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  775. type.GetGenericArguments()[0] :
  776. type;
  777. }
  778. }
  779. }
  780. //-------- Scenario 3174
  781. namespace Scenario3174{
  782. public class Test
  783. {
  784. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "longq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  785. public static Expression longq_ArrayIndex__() {
  786. if(Main() != 0 ) {
  787. throw new Exception();
  788. } else {
  789. return Expression.Constant(0);
  790. }
  791. }
  792. public static int Main()
  793. {
  794. Ext.StartCapture();
  795. bool success = false;
  796. try
  797. {
  798. success = check_longq_ArrayIndex();
  799. }
  800. finally
  801. {
  802. Ext.StopCapture();
  803. }
  804. return success ? 0 : 1;
  805. }
  806. static bool check_longq_ArrayIndex() {
  807. return checkEx_longq_ArrayIndex(null, -1) &
  808. checkEx_longq_ArrayIndex(null, 0) &
  809. checkEx_longq_ArrayIndex(null, 1) &
  810. check_longq_ArrayIndex(genArrlongq_ArrayIndex(0)) &
  811. check_longq_ArrayIndex(genArrlongq_ArrayIndex(1)) &
  812. check_longq_ArrayIndex(genArrlongq_ArrayIndex(5));
  813. }
  814. static long?[] genArrlongq_ArrayIndex(int size) {
  815. long?[] vals = new long?[] { 0, 1, -1, long.MinValue, long.MaxValue };
  816. long?[] result = new long?[size];
  817. for (int i = 0; i < size; i++) {
  818. result[i] = vals[i % vals.Length];
  819. }
  820. return result;
  821. }
  822. static bool check_longq_ArrayIndex(long?[] val) {
  823. bool success = checkEx_longq_ArrayIndex(val, -1);
  824. for (int i = 0; i < val.Length; i++) {
  825. success &= check_longq_ArrayIndex(val, 0);
  826. }
  827. success &= checkEx_longq_ArrayIndex(val, val.Length);
  828. return success;
  829. }
  830. static bool checkEx_longq_ArrayIndex(long?[] val, int index) {
  831. try {
  832. check_longq_ArrayIndex(val, index);
  833. Console.WriteLine("longq_ArrayIndex[" + index + "] failed");
  834. return false;
  835. }
  836. catch {
  837. return true;
  838. }
  839. }
  840. static bool check_longq_ArrayIndex(long?[] val, int index) {
  841. Expression<Func<long?>> e =
  842. Expression.Lambda<Func<long?>>(
  843. Expression.ArrayIndex(Expression.Constant(val, typeof(long?[])),
  844. Expression.Constant(index, typeof(int))),
  845. new System.Collections.Generic.List<ParameterExpression>());
  846. Func<long?> f = e.Compile();
  847. return object.Equals(f(), val[index]);
  848. }
  849. }
  850. public static class Ext {
  851. public static void StartCapture() {
  852. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  853. // m.Invoke(null, new object[] { "test.dll" });
  854. }
  855. public static void StopCapture() {
  856. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  857. // m.Invoke(null, new object[0]);
  858. }
  859. public static bool IsIntegralOrEnum(Type type) {
  860. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  861. case TypeCode.Byte:
  862. case TypeCode.SByte:
  863. case TypeCode.Int16:
  864. case TypeCode.Int32:
  865. case TypeCode.Int64:
  866. case TypeCode.UInt16:
  867. case TypeCode.UInt32:
  868. case TypeCode.UInt64:
  869. return true;
  870. default:
  871. return false;
  872. }
  873. }
  874. public static bool IsFloating(Type type) {
  875. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  876. case TypeCode.Single:
  877. case TypeCode.Double:
  878. return true;
  879. default:
  880. return false;
  881. }
  882. }
  883. public static Type GetNonNullableType(Type type) {
  884. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  885. type.GetGenericArguments()[0] :
  886. type;
  887. }
  888. }
  889. }
  890. //-------- Scenario 3175
  891. namespace Scenario3175{
  892. public class Test
  893. {
  894. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "floatq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  895. public static Expression floatq_ArrayIndex__() {
  896. if(Main() != 0 ) {
  897. throw new Exception();
  898. } else {
  899. return Expression.Constant(0);
  900. }
  901. }
  902. public static int Main()
  903. {
  904. Ext.StartCapture();
  905. bool success = false;
  906. try
  907. {
  908. success = check_floatq_ArrayIndex();
  909. }
  910. finally
  911. {
  912. Ext.StopCapture();
  913. }
  914. return success ? 0 : 1;
  915. }
  916. static bool check_floatq_ArrayIndex() {
  917. return checkEx_floatq_ArrayIndex(null, -1) &
  918. checkEx_floatq_ArrayIndex(null, 0) &
  919. checkEx_floatq_ArrayIndex(null, 1) &
  920. check_floatq_ArrayIndex(genArrfloatq_ArrayIndex(0)) &
  921. check_floatq_ArrayIndex(genArrfloatq_ArrayIndex(1)) &
  922. check_floatq_ArrayIndex(genArrfloatq_ArrayIndex(5));
  923. }
  924. static float?[] genArrfloatq_ArrayIndex(int size) {
  925. float?[] vals = new float?[] { 0, 1, -1, float.MinValue, float.MaxValue, float.Epsilon, float.NegativeInfinity, float.PositiveInfinity, float.NaN };
  926. float?[] result = new float?[size];
  927. for (int i = 0; i < size; i++) {
  928. result[i] = vals[i % vals.Length];
  929. }
  930. return result;
  931. }
  932. static bool check_floatq_ArrayIndex(float?[] val) {
  933. bool success = checkEx_floatq_ArrayIndex(val, -1);
  934. for (int i = 0; i < val.Length; i++) {
  935. success &= check_floatq_ArrayIndex(val, 0);
  936. }
  937. success &= checkEx_floatq_ArrayIndex(val, val.Length);
  938. return success;
  939. }
  940. static bool checkEx_floatq_ArrayIndex(float?[] val, int index) {
  941. try {
  942. check_floatq_ArrayIndex(val, index);
  943. Console.WriteLine("floatq_ArrayIndex[" + index + "] failed");
  944. return false;
  945. }
  946. catch {
  947. return true;
  948. }
  949. }
  950. static bool check_floatq_ArrayIndex(float?[] val, int index) {
  951. Expression<Func<float?>> e =
  952. Expression.Lambda<Func<float?>>(
  953. Expression.ArrayIndex(Expression.Constant(val, typeof(float?[])),
  954. Expression.Constant(index, typeof(int))),
  955. new System.Collections.Generic.List<ParameterExpression>());
  956. Func<float?> f = e.Compile();
  957. return object.Equals(f(), val[index]);
  958. }
  959. }
  960. public static class Ext {
  961. public static void StartCapture() {
  962. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  963. // m.Invoke(null, new object[] { "test.dll" });
  964. }
  965. public static void StopCapture() {
  966. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  967. // m.Invoke(null, new object[0]);
  968. }
  969. public static bool IsIntegralOrEnum(Type type) {
  970. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  971. case TypeCode.Byte:
  972. case TypeCode.SByte:
  973. case TypeCode.Int16:
  974. case TypeCode.Int32:
  975. case TypeCode.Int64:
  976. case TypeCode.UInt16:
  977. case TypeCode.UInt32:
  978. case TypeCode.UInt64:
  979. return true;
  980. default:
  981. return false;
  982. }
  983. }
  984. public static bool IsFloating(Type type) {
  985. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  986. case TypeCode.Single:
  987. case TypeCode.Double:
  988. return true;
  989. default:
  990. return false;
  991. }
  992. }
  993. public static Type GetNonNullableType(Type type) {
  994. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  995. type.GetGenericArguments()[0] :
  996. type;
  997. }
  998. }
  999. }
  1000. //-------- Scenario 3176
  1001. namespace Scenario3176{
  1002. public class Test
  1003. {
  1004. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "doubleq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1005. public static Expression doubleq_ArrayIndex__() {
  1006. if(Main() != 0 ) {
  1007. throw new Exception();
  1008. } else {
  1009. return Expression.Constant(0);
  1010. }
  1011. }
  1012. public static int Main()
  1013. {
  1014. Ext.StartCapture();
  1015. bool success = false;
  1016. try
  1017. {
  1018. success = check_doubleq_ArrayIndex();
  1019. }
  1020. finally
  1021. {
  1022. Ext.StopCapture();
  1023. }
  1024. return success ? 0 : 1;
  1025. }
  1026. static bool check_doubleq_ArrayIndex() {
  1027. return checkEx_doubleq_ArrayIndex(null, -1) &
  1028. checkEx_doubleq_ArrayIndex(null, 0) &
  1029. checkEx_doubleq_ArrayIndex(null, 1) &
  1030. check_doubleq_ArrayIndex(genArrdoubleq_ArrayIndex(0)) &
  1031. check_doubleq_ArrayIndex(genArrdoubleq_ArrayIndex(1)) &
  1032. check_doubleq_ArrayIndex(genArrdoubleq_ArrayIndex(5));
  1033. }
  1034. static double?[] genArrdoubleq_ArrayIndex(int size) {
  1035. double?[] vals = new double?[] { 0, 1, -1, double.MinValue, double.MaxValue, double.Epsilon, double.NegativeInfinity, double.PositiveInfinity, double.NaN };
  1036. double?[] result = new double?[size];
  1037. for (int i = 0; i < size; i++) {
  1038. result[i] = vals[i % vals.Length];
  1039. }
  1040. return result;
  1041. }
  1042. static bool check_doubleq_ArrayIndex(double?[] val) {
  1043. bool success = checkEx_doubleq_ArrayIndex(val, -1);
  1044. for (int i = 0; i < val.Length; i++) {
  1045. success &= check_doubleq_ArrayIndex(val, 0);
  1046. }
  1047. success &= checkEx_doubleq_ArrayIndex(val, val.Length);
  1048. return success;
  1049. }
  1050. static bool checkEx_doubleq_ArrayIndex(double?[] val, int index) {
  1051. try {
  1052. check_doubleq_ArrayIndex(val, index);
  1053. Console.WriteLine("doubleq_ArrayIndex[" + index + "] failed");
  1054. return false;
  1055. }
  1056. catch {
  1057. return true;
  1058. }
  1059. }
  1060. static bool check_doubleq_ArrayIndex(double?[] val, int index) {
  1061. Expression<Func<double?>> e =
  1062. Expression.Lambda<Func<double?>>(
  1063. Expression.ArrayIndex(Expression.Constant(val, typeof(double?[])),
  1064. Expression.Constant(index, typeof(int))),
  1065. new System.Collections.Generic.List<ParameterExpression>());
  1066. Func<double?> f = e.Compile();
  1067. return object.Equals(f(), val[index]);
  1068. }
  1069. }
  1070. public static class Ext {
  1071. public static void StartCapture() {
  1072. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1073. // m.Invoke(null, new object[] { "test.dll" });
  1074. }
  1075. public static void StopCapture() {
  1076. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1077. // m.Invoke(null, new object[0]);
  1078. }
  1079. public static bool IsIntegralOrEnum(Type type) {
  1080. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1081. case TypeCode.Byte:
  1082. case TypeCode.SByte:
  1083. case TypeCode.Int16:
  1084. case TypeCode.Int32:
  1085. case TypeCode.Int64:
  1086. case TypeCode.UInt16:
  1087. case TypeCode.UInt32:
  1088. case TypeCode.UInt64:
  1089. return true;
  1090. default:
  1091. return false;
  1092. }
  1093. }
  1094. public static bool IsFloating(Type type) {
  1095. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1096. case TypeCode.Single:
  1097. case TypeCode.Double:
  1098. return true;
  1099. default:
  1100. return false;
  1101. }
  1102. }
  1103. public static Type GetNonNullableType(Type type) {
  1104. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1105. type.GetGenericArguments()[0] :
  1106. type;
  1107. }
  1108. }
  1109. }
  1110. //-------- Scenario 3177
  1111. namespace Scenario3177{
  1112. public class Test
  1113. {
  1114. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "decimalq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1115. public static Expression decimalq_ArrayIndex__() {
  1116. if(Main() != 0 ) {
  1117. throw new Exception();
  1118. } else {
  1119. return Expression.Constant(0);
  1120. }
  1121. }
  1122. public static int Main()
  1123. {
  1124. Ext.StartCapture();
  1125. bool success = false;
  1126. try
  1127. {
  1128. success = check_decimalq_ArrayIndex();
  1129. }
  1130. finally
  1131. {
  1132. Ext.StopCapture();
  1133. }
  1134. return success ? 0 : 1;
  1135. }
  1136. static bool check_decimalq_ArrayIndex() {
  1137. return checkEx_decimalq_ArrayIndex(null, -1) &
  1138. checkEx_decimalq_ArrayIndex(null, 0) &
  1139. checkEx_decimalq_ArrayIndex(null, 1) &
  1140. check_decimalq_ArrayIndex(genArrdecimalq_ArrayIndex(0)) &
  1141. check_decimalq_ArrayIndex(genArrdecimalq_ArrayIndex(1)) &
  1142. check_decimalq_ArrayIndex(genArrdecimalq_ArrayIndex(5));
  1143. }
  1144. static decimal?[] genArrdecimalq_ArrayIndex(int size) {
  1145. decimal?[] vals = new decimal?[] { decimal.Zero, decimal.One, decimal.MinusOne, decimal.MinValue, decimal.MaxValue };
  1146. decimal?[] result = new decimal?[size];
  1147. for (int i = 0; i < size; i++) {
  1148. result[i] = vals[i % vals.Length];
  1149. }
  1150. return result;
  1151. }
  1152. static bool check_decimalq_ArrayIndex(decimal?[] val) {
  1153. bool success = checkEx_decimalq_ArrayIndex(val, -1);
  1154. for (int i = 0; i < val.Length; i++) {
  1155. success &= check_decimalq_ArrayIndex(val, 0);
  1156. }
  1157. success &= checkEx_decimalq_ArrayIndex(val, val.Length);
  1158. return success;
  1159. }
  1160. static bool checkEx_decimalq_ArrayIndex(decimal?[] val, int index) {
  1161. try {
  1162. check_decimalq_ArrayIndex(val, index);
  1163. Console.WriteLine("decimalq_ArrayIndex[" + index + "] failed");
  1164. return false;
  1165. }
  1166. catch {
  1167. return true;
  1168. }
  1169. }
  1170. static bool check_decimalq_ArrayIndex(decimal?[] val, int index) {
  1171. Expression<Func<decimal?>> e =
  1172. Expression.Lambda<Func<decimal?>>(
  1173. Expression.ArrayIndex(Expression.Constant(val, typeof(decimal?[])),
  1174. Expression.Constant(index, typeof(int))),
  1175. new System.Collections.Generic.List<ParameterExpression>());
  1176. Func<decimal?> f = e.Compile();
  1177. return object.Equals(f(), val[index]);
  1178. }
  1179. }
  1180. public static class Ext {
  1181. public static void StartCapture() {
  1182. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1183. // m.Invoke(null, new object[] { "test.dll" });
  1184. }
  1185. public static void StopCapture() {
  1186. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1187. // m.Invoke(null, new object[0]);
  1188. }
  1189. public static bool IsIntegralOrEnum(Type type) {
  1190. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1191. case TypeCode.Byte:
  1192. case TypeCode.SByte:
  1193. case TypeCode.Int16:
  1194. case TypeCode.Int32:
  1195. case TypeCode.Int64:
  1196. case TypeCode.UInt16:
  1197. case TypeCode.UInt32:
  1198. case TypeCode.UInt64:
  1199. return true;
  1200. default:
  1201. return false;
  1202. }
  1203. }
  1204. public static bool IsFloating(Type type) {
  1205. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1206. case TypeCode.Single:
  1207. case TypeCode.Double:
  1208. return true;
  1209. default:
  1210. return false;
  1211. }
  1212. }
  1213. public static Type GetNonNullableType(Type type) {
  1214. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1215. type.GetGenericArguments()[0] :
  1216. type;
  1217. }
  1218. }
  1219. }
  1220. //-------- Scenario 3178
  1221. namespace Scenario3178{
  1222. public class Test
  1223. {
  1224. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "charq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1225. public static Expression charq_ArrayIndex__() {
  1226. if(Main() != 0 ) {
  1227. throw new Exception();
  1228. } else {
  1229. return Expression.Constant(0);
  1230. }
  1231. }
  1232. public static int Main()
  1233. {
  1234. Ext.StartCapture();
  1235. bool success = false;
  1236. try
  1237. {
  1238. success = check_charq_ArrayIndex();
  1239. }
  1240. finally
  1241. {
  1242. Ext.StopCapture();
  1243. }
  1244. return success ? 0 : 1;
  1245. }
  1246. static bool check_charq_ArrayIndex() {
  1247. return checkEx_charq_ArrayIndex(null, -1) &
  1248. checkEx_charq_ArrayIndex(null, 0) &
  1249. checkEx_charq_ArrayIndex(null, 1) &
  1250. check_charq_ArrayIndex(genArrcharq_ArrayIndex(0)) &
  1251. check_charq_ArrayIndex(genArrcharq_ArrayIndex(1)) &
  1252. check_charq_ArrayIndex(genArrcharq_ArrayIndex(5));
  1253. }
  1254. static char?[] genArrcharq_ArrayIndex(int size) {
  1255. char?[] vals = new char?[] { '\0', '\b', 'A', '\uffff' };
  1256. char?[] result = new char?[size];
  1257. for (int i = 0; i < size; i++) {
  1258. result[i] = vals[i % vals.Length];
  1259. }
  1260. return result;
  1261. }
  1262. static bool check_charq_ArrayIndex(char?[] val) {
  1263. bool success = checkEx_charq_ArrayIndex(val, -1);
  1264. for (int i = 0; i < val.Length; i++) {
  1265. success &= check_charq_ArrayIndex(val, 0);
  1266. }
  1267. success &= checkEx_charq_ArrayIndex(val, val.Length);
  1268. return success;
  1269. }
  1270. static bool checkEx_charq_ArrayIndex(char?[] val, int index) {
  1271. try {
  1272. check_charq_ArrayIndex(val, index);
  1273. Console.WriteLine("charq_ArrayIndex[" + index + "] failed");
  1274. return false;
  1275. }
  1276. catch {
  1277. return true;
  1278. }
  1279. }
  1280. static bool check_charq_ArrayIndex(char?[] val, int index) {
  1281. Expression<Func<char?>> e =
  1282. Expression.Lambda<Func<char?>>(
  1283. Expression.ArrayIndex(Expression.Constant(val, typeof(char?[])),
  1284. Expression.Constant(index, typeof(int))),
  1285. new System.Collections.Generic.List<ParameterExpression>());
  1286. Func<char?> f = e.Compile();
  1287. return object.Equals(f(), val[index]);
  1288. }
  1289. }
  1290. public static class Ext {
  1291. public static void StartCapture() {
  1292. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1293. // m.Invoke(null, new object[] { "test.dll" });
  1294. }
  1295. public static void StopCapture() {
  1296. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1297. // m.Invoke(null, new object[0]);
  1298. }
  1299. public static bool IsIntegralOrEnum(Type type) {
  1300. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1301. case TypeCode.Byte:
  1302. case TypeCode.SByte:
  1303. case TypeCode.Int16:
  1304. case TypeCode.Int32:
  1305. case TypeCode.Int64:
  1306. case TypeCode.UInt16:
  1307. case TypeCode.UInt32:
  1308. case TypeCode.UInt64:
  1309. return true;
  1310. default:
  1311. return false;
  1312. }
  1313. }
  1314. public static bool IsFloating(Type type) {
  1315. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1316. case TypeCode.Single:
  1317. case TypeCode.Double:
  1318. return true;
  1319. default:
  1320. return false;
  1321. }
  1322. }
  1323. public static Type GetNonNullableType(Type type) {
  1324. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1325. type.GetGenericArguments()[0] :
  1326. type;
  1327. }
  1328. }
  1329. }
  1330. //-------- Scenario 3179
  1331. namespace Scenario3179{
  1332. public class Test
  1333. {
  1334. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "boolq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1335. public static Expression boolq_ArrayIndex__() {
  1336. if(Main() != 0 ) {
  1337. throw new Exception();
  1338. } else {
  1339. return Expression.Constant(0);
  1340. }
  1341. }
  1342. public static int Main()
  1343. {
  1344. Ext.StartCapture();
  1345. bool success = false;
  1346. try
  1347. {
  1348. success = check_boolq_ArrayIndex();
  1349. }
  1350. finally
  1351. {
  1352. Ext.StopCapture();
  1353. }
  1354. return success ? 0 : 1;
  1355. }
  1356. static bool check_boolq_ArrayIndex() {
  1357. return checkEx_boolq_ArrayIndex(null, -1) &
  1358. checkEx_boolq_ArrayIndex(null, 0) &
  1359. checkEx_boolq_ArrayIndex(null, 1) &
  1360. check_boolq_ArrayIndex(genArrboolq_ArrayIndex(0)) &
  1361. check_boolq_ArrayIndex(genArrboolq_ArrayIndex(1)) &
  1362. check_boolq_ArrayIndex(genArrboolq_ArrayIndex(5));
  1363. }
  1364. static bool?[] genArrboolq_ArrayIndex(int size) {
  1365. bool?[] vals = new bool?[] { true, false };
  1366. bool?[] result = new bool?[size];
  1367. for (int i = 0; i < size; i++) {
  1368. result[i] = vals[i % vals.Length];
  1369. }
  1370. return result;
  1371. }
  1372. static bool check_boolq_ArrayIndex(bool?[] val) {
  1373. bool success = checkEx_boolq_ArrayIndex(val, -1);
  1374. for (int i = 0; i < val.Length; i++) {
  1375. success &= check_boolq_ArrayIndex(val, 0);
  1376. }
  1377. success &= checkEx_boolq_ArrayIndex(val, val.Length);
  1378. return success;
  1379. }
  1380. static bool checkEx_boolq_ArrayIndex(bool?[] val, int index) {
  1381. try {
  1382. check_boolq_ArrayIndex(val, index);
  1383. Console.WriteLine("boolq_ArrayIndex[" + index + "] failed");
  1384. return false;
  1385. }
  1386. catch {
  1387. return true;
  1388. }
  1389. }
  1390. static bool check_boolq_ArrayIndex(bool?[] val, int index) {
  1391. Expression<Func<bool?>> e =
  1392. Expression.Lambda<Func<bool?>>(
  1393. Expression.ArrayIndex(Expression.Constant(val, typeof(bool?[])),
  1394. Expression.Constant(index, typeof(int))),
  1395. new System.Collections.Generic.List<ParameterExpression>());
  1396. Func<bool?> f = e.Compile();
  1397. return object.Equals(f(), val[index]);
  1398. }
  1399. }
  1400. public static class Ext {
  1401. public static void StartCapture() {
  1402. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1403. // m.Invoke(null, new object[] { "test.dll" });
  1404. }
  1405. public static void StopCapture() {
  1406. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1407. // m.Invoke(null, new object[0]);
  1408. }
  1409. public static bool IsIntegralOrEnum(Type type) {
  1410. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1411. case TypeCode.Byte:
  1412. case TypeCode.SByte:
  1413. case TypeCode.Int16:
  1414. case TypeCode.Int32:
  1415. case TypeCode.Int64:
  1416. case TypeCode.UInt16:
  1417. case TypeCode.UInt32:
  1418. case TypeCode.UInt64:
  1419. return true;
  1420. default:
  1421. return false;
  1422. }
  1423. }
  1424. public static bool IsFloating(Type type) {
  1425. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1426. case TypeCode.Single:
  1427. case TypeCode.Double:
  1428. return true;
  1429. default:
  1430. return false;
  1431. }
  1432. }
  1433. public static Type GetNonNullableType(Type type) {
  1434. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1435. type.GetGenericArguments()[0] :
  1436. type;
  1437. }
  1438. }
  1439. }
  1440. //-------- Scenario 3180
  1441. namespace Scenario3180{
  1442. public class Test
  1443. {
  1444. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Sq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1445. public static Expression Sq_ArrayIndex__() {
  1446. if(Main() != 0 ) {
  1447. throw new Exception();
  1448. } else {
  1449. return Expression.Constant(0);
  1450. }
  1451. }
  1452. public static int Main()
  1453. {
  1454. Ext.StartCapture();
  1455. bool success = false;
  1456. try
  1457. {
  1458. success = check_Sq_ArrayIndex();
  1459. }
  1460. finally
  1461. {
  1462. Ext.StopCapture();
  1463. }
  1464. return success ? 0 : 1;
  1465. }
  1466. static bool check_Sq_ArrayIndex() {
  1467. return checkEx_Sq_ArrayIndex(null, -1) &
  1468. checkEx_Sq_ArrayIndex(null, 0) &
  1469. checkEx_Sq_ArrayIndex(null, 1) &
  1470. check_Sq_ArrayIndex(genArrSq_ArrayIndex(0)) &
  1471. check_Sq_ArrayIndex(genArrSq_ArrayIndex(1)) &
  1472. check_Sq_ArrayIndex(genArrSq_ArrayIndex(5));
  1473. }
  1474. static S?[] genArrSq_ArrayIndex(int size) {
  1475. S?[] vals = new S?[] { default(S), new S() };
  1476. S?[] result = new S?[size];
  1477. for (int i = 0; i < size; i++) {
  1478. result[i] = vals[i % vals.Length];
  1479. }
  1480. return result;
  1481. }
  1482. static bool check_Sq_ArrayIndex(S?[] val) {
  1483. bool success = checkEx_Sq_ArrayIndex(val, -1);
  1484. for (int i = 0; i < val.Length; i++) {
  1485. success &= check_Sq_ArrayIndex(val, 0);
  1486. }
  1487. success &= checkEx_Sq_ArrayIndex(val, val.Length);
  1488. return success;
  1489. }
  1490. static bool checkEx_Sq_ArrayIndex(S?[] val, int index) {
  1491. try {
  1492. check_Sq_ArrayIndex(val, index);
  1493. Console.WriteLine("Sq_ArrayIndex[" + index + "] failed");
  1494. return false;
  1495. }
  1496. catch {
  1497. return true;
  1498. }
  1499. }
  1500. static bool check_Sq_ArrayIndex(S?[] val, int index) {
  1501. Expression<Func<S?>> e =
  1502. Expression.Lambda<Func<S?>>(
  1503. Expression.ArrayIndex(Expression.Constant(val, typeof(S?[])),
  1504. Expression.Constant(index, typeof(int))),
  1505. new System.Collections.Generic.List<ParameterExpression>());
  1506. Func<S?> f = e.Compile();
  1507. return object.Equals(f(), val[index]);
  1508. }
  1509. }
  1510. public static class Ext {
  1511. public static void StartCapture() {
  1512. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1513. // m.Invoke(null, new object[] { "test.dll" });
  1514. }
  1515. public static void StopCapture() {
  1516. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1517. // m.Invoke(null, new object[0]);
  1518. }
  1519. public static bool IsIntegralOrEnum(Type type) {
  1520. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1521. case TypeCode.Byte:
  1522. case TypeCode.SByte:
  1523. case TypeCode.Int16:
  1524. case TypeCode.Int32:
  1525. case TypeCode.Int64:
  1526. case TypeCode.UInt16:
  1527. case TypeCode.UInt32:
  1528. case TypeCode.UInt64:
  1529. return true;
  1530. default:
  1531. return false;
  1532. }
  1533. }
  1534. public static bool IsFloating(Type type) {
  1535. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1536. case TypeCode.Single:
  1537. case TypeCode.Double:
  1538. return true;
  1539. default:
  1540. return false;
  1541. }
  1542. }
  1543. public static Type GetNonNullableType(Type type) {
  1544. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1545. type.GetGenericArguments()[0] :
  1546. type;
  1547. }
  1548. }
  1549. interface I {
  1550. void M();
  1551. }
  1552. public class C : IEquatable<C>, I {
  1553. void I.M() {
  1554. }
  1555. public override bool Equals(object o) {
  1556. return o is C && Equals((C) o);
  1557. }
  1558. public bool Equals(C c) {
  1559. return c != null;
  1560. }
  1561. public override int GetHashCode() {
  1562. return 0;
  1563. }
  1564. }
  1565. public class D : C, IEquatable<D> {
  1566. public int Val;
  1567. public D() {
  1568. }
  1569. public D(int val) {
  1570. Val = val;
  1571. }
  1572. public override bool Equals(object o) {
  1573. return o is D && Equals((D) o);
  1574. }
  1575. public bool Equals(D d) {
  1576. return d != null && d.Val == Val;
  1577. }
  1578. public override int GetHashCode() {
  1579. return Val;
  1580. }
  1581. }
  1582. public enum E {
  1583. A=1, B=2
  1584. }
  1585. public enum El : long {
  1586. A, B, C
  1587. }
  1588. public struct S : IEquatable<S> {
  1589. public override bool Equals(object o) {
  1590. return (o is S) && Equals((S) o);
  1591. }
  1592. public bool Equals(S other) {
  1593. return true;
  1594. }
  1595. public override int GetHashCode() {
  1596. return 0;
  1597. }
  1598. }
  1599. public struct Sp : IEquatable<Sp> {
  1600. public Sp(int i, double d) {
  1601. I = i;
  1602. D = d;
  1603. }
  1604. public int I;
  1605. public double D;
  1606. public override bool Equals(object o) {
  1607. return (o is Sp) && Equals((Sp) o);
  1608. }
  1609. public bool Equals(Sp other) {
  1610. return other.I == I && other.D == D;
  1611. }
  1612. public override int GetHashCode() {
  1613. return I.GetHashCode() ^ D.GetHashCode();
  1614. }
  1615. }
  1616. public struct Ss : IEquatable<Ss> {
  1617. public Ss(S s) {
  1618. Val = s;
  1619. }
  1620. public S Val;
  1621. public override bool Equals(object o) {
  1622. return (o is Ss) && Equals((Ss) o);
  1623. }
  1624. public bool Equals(Ss other) {
  1625. return other.Val.Equals(Val);
  1626. }
  1627. public override int GetHashCode() {
  1628. return Val.GetHashCode();
  1629. }
  1630. }
  1631. public struct Sc : IEquatable<Sc> {
  1632. public Sc(string s) {
  1633. S = s;
  1634. }
  1635. public string S;
  1636. public override bool Equals(object o) {
  1637. return (o is Sc) && Equals((Sc) o);
  1638. }
  1639. public bool Equals(Sc other) {
  1640. return other.S == S;
  1641. }
  1642. public override int GetHashCode() {
  1643. return S.GetHashCode();
  1644. }
  1645. }
  1646. public struct Scs : IEquatable<Scs> {
  1647. public Scs(string s, S val) {
  1648. S = s;
  1649. Val = val;
  1650. }
  1651. public string S;
  1652. public S Val;
  1653. public override bool Equals(object o) {
  1654. return (o is Scs) && Equals((Scs) o);
  1655. }
  1656. public bool Equals(Scs other) {
  1657. return other.S == S && other.Val.Equals(Val);
  1658. }
  1659. public override int GetHashCode() {
  1660. return S.GetHashCode() ^ Val.GetHashCode();
  1661. }
  1662. }
  1663. }
  1664. //-------- Scenario 3181
  1665. namespace Scenario3181{
  1666. public class Test
  1667. {
  1668. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Spq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1669. public static Expression Spq_ArrayIndex__() {
  1670. if(Main() != 0 ) {
  1671. throw new Exception();
  1672. } else {
  1673. return Expression.Constant(0);
  1674. }
  1675. }
  1676. public static int Main()
  1677. {
  1678. Ext.StartCapture();
  1679. bool success = false;
  1680. try
  1681. {
  1682. success = check_Spq_ArrayIndex();
  1683. }
  1684. finally
  1685. {
  1686. Ext.StopCapture();
  1687. }
  1688. return success ? 0 : 1;
  1689. }
  1690. static bool check_Spq_ArrayIndex() {
  1691. return checkEx_Spq_ArrayIndex(null, -1) &
  1692. checkEx_Spq_ArrayIndex(null, 0) &
  1693. checkEx_Spq_ArrayIndex(null, 1) &
  1694. check_Spq_ArrayIndex(genArrSpq_ArrayIndex(0)) &
  1695. check_Spq_ArrayIndex(genArrSpq_ArrayIndex(1)) &
  1696. check_Spq_ArrayIndex(genArrSpq_ArrayIndex(5));
  1697. }
  1698. static Sp?[] genArrSpq_ArrayIndex(int size) {
  1699. Sp?[] vals = new Sp?[] { default(Sp), new Sp(), new Sp(5,5.0) };
  1700. Sp?[] result = new Sp?[size];
  1701. for (int i = 0; i < size; i++) {
  1702. result[i] = vals[i % vals.Length];
  1703. }
  1704. return result;
  1705. }
  1706. static bool check_Spq_ArrayIndex(Sp?[] val) {
  1707. bool success = checkEx_Spq_ArrayIndex(val, -1);
  1708. for (int i = 0; i < val.Length; i++) {
  1709. success &= check_Spq_ArrayIndex(val, 0);
  1710. }
  1711. success &= checkEx_Spq_ArrayIndex(val, val.Length);
  1712. return success;
  1713. }
  1714. static bool checkEx_Spq_ArrayIndex(Sp?[] val, int index) {
  1715. try {
  1716. check_Spq_ArrayIndex(val, index);
  1717. Console.WriteLine("Spq_ArrayIndex[" + index + "] failed");
  1718. return false;
  1719. }
  1720. catch {
  1721. return true;
  1722. }
  1723. }
  1724. static bool check_Spq_ArrayIndex(Sp?[] val, int index) {
  1725. Expression<Func<Sp?>> e =
  1726. Expression.Lambda<Func<Sp?>>(
  1727. Expression.ArrayIndex(Expression.Constant(val, typeof(Sp?[])),
  1728. Expression.Constant(index, typeof(int))),
  1729. new System.Collections.Generic.List<ParameterExpression>());
  1730. Func<Sp?> f = e.Compile();
  1731. return object.Equals(f(), val[index]);
  1732. }
  1733. }
  1734. public static class Ext {
  1735. public static void StartCapture() {
  1736. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1737. // m.Invoke(null, new object[] { "test.dll" });
  1738. }
  1739. public static void StopCapture() {
  1740. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1741. // m.Invoke(null, new object[0]);
  1742. }
  1743. public static bool IsIntegralOrEnum(Type type) {
  1744. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1745. case TypeCode.Byte:
  1746. case TypeCode.SByte:
  1747. case TypeCode.Int16:
  1748. case TypeCode.Int32:
  1749. case TypeCode.Int64:
  1750. case TypeCode.UInt16:
  1751. case TypeCode.UInt32:
  1752. case TypeCode.UInt64:
  1753. return true;
  1754. default:
  1755. return false;
  1756. }
  1757. }
  1758. public static bool IsFloating(Type type) {
  1759. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1760. case TypeCode.Single:
  1761. case TypeCode.Double:
  1762. return true;
  1763. default:
  1764. return false;
  1765. }
  1766. }
  1767. public static Type GetNonNullableType(Type type) {
  1768. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1769. type.GetGenericArguments()[0] :
  1770. type;
  1771. }
  1772. }
  1773. interface I {
  1774. void M();
  1775. }
  1776. public class C : IEquatable<C>, I {
  1777. void I.M() {
  1778. }
  1779. public override bool Equals(object o) {
  1780. return o is C && Equals((C) o);
  1781. }
  1782. public bool Equals(C c) {
  1783. return c != null;
  1784. }
  1785. public override int GetHashCode() {
  1786. return 0;
  1787. }
  1788. }
  1789. public class D : C, IEquatable<D> {
  1790. public int Val;
  1791. public D() {
  1792. }
  1793. public D(int val) {
  1794. Val = val;
  1795. }
  1796. public override bool Equals(object o) {
  1797. return o is D && Equals((D) o);
  1798. }
  1799. public bool Equals(D d) {
  1800. return d != null && d.Val == Val;
  1801. }
  1802. public override int GetHashCode() {
  1803. return Val;
  1804. }
  1805. }
  1806. public enum E {
  1807. A=1, B=2
  1808. }
  1809. public enum El : long {
  1810. A, B, C
  1811. }
  1812. public struct S : IEquatable<S> {
  1813. public override bool Equals(object o) {
  1814. return (o is S) && Equals((S) o);
  1815. }
  1816. public bool Equals(S other) {
  1817. return true;
  1818. }
  1819. public override int GetHashCode() {
  1820. return 0;
  1821. }
  1822. }
  1823. public struct Sp : IEquatable<Sp> {
  1824. public Sp(int i, double d) {
  1825. I = i;
  1826. D = d;
  1827. }
  1828. public int I;
  1829. public double D;
  1830. public override bool Equals(object o) {
  1831. return (o is Sp) && Equals((Sp) o);
  1832. }
  1833. public bool Equals(Sp other) {
  1834. return other.I == I && other.D == D;
  1835. }
  1836. public override int GetHashCode() {
  1837. return I.GetHashCode() ^ D.GetHashCode();
  1838. }
  1839. }
  1840. public struct Ss : IEquatable<Ss> {
  1841. public Ss(S s) {
  1842. Val = s;
  1843. }
  1844. public S Val;
  1845. public override bool Equals(object o) {
  1846. return (o is Ss) && Equals((Ss) o);
  1847. }
  1848. public bool Equals(Ss other) {
  1849. return other.Val.Equals(Val);
  1850. }
  1851. public override int GetHashCode() {
  1852. return Val.GetHashCode();
  1853. }
  1854. }
  1855. public struct Sc : IEquatable<Sc> {
  1856. public Sc(string s) {
  1857. S = s;
  1858. }
  1859. public string S;
  1860. public override bool Equals(object o) {
  1861. return (o is Sc) && Equals((Sc) o);
  1862. }
  1863. public bool Equals(Sc other) {
  1864. return other.S == S;
  1865. }
  1866. public override int GetHashCode() {
  1867. return S.GetHashCode();
  1868. }
  1869. }
  1870. public struct Scs : IEquatable<Scs> {
  1871. public Scs(string s, S val) {
  1872. S = s;
  1873. Val = val;
  1874. }
  1875. public string S;
  1876. public S Val;
  1877. public override bool Equals(object o) {
  1878. return (o is Scs) && Equals((Scs) o);
  1879. }
  1880. public bool Equals(Scs other) {
  1881. return other.S == S && other.Val.Equals(Val);
  1882. }
  1883. public override int GetHashCode() {
  1884. return S.GetHashCode() ^ Val.GetHashCode();
  1885. }
  1886. }
  1887. }
  1888. //-------- Scenario 3182
  1889. namespace Scenario3182{
  1890. public class Test
  1891. {
  1892. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Ssq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1893. public static Expression Ssq_ArrayIndex__() {
  1894. if(Main() != 0 ) {
  1895. throw new Exception();
  1896. } else {
  1897. return Expression.Constant(0);
  1898. }
  1899. }
  1900. public static int Main()
  1901. {
  1902. Ext.StartCapture();
  1903. bool success = false;
  1904. try
  1905. {
  1906. success = check_Ssq_ArrayIndex();
  1907. }
  1908. finally
  1909. {
  1910. Ext.StopCapture();
  1911. }
  1912. return success ? 0 : 1;
  1913. }
  1914. static bool check_Ssq_ArrayIndex() {
  1915. return checkEx_Ssq_ArrayIndex(null, -1) &
  1916. checkEx_Ssq_ArrayIndex(null, 0) &
  1917. checkEx_Ssq_ArrayIndex(null, 1) &
  1918. check_Ssq_ArrayIndex(genArrSsq_ArrayIndex(0)) &
  1919. check_Ssq_ArrayIndex(genArrSsq_ArrayIndex(1)) &
  1920. check_Ssq_ArrayIndex(genArrSsq_ArrayIndex(5));
  1921. }
  1922. static Ss?[] genArrSsq_ArrayIndex(int size) {
  1923. Ss?[] vals = new Ss?[] { default(Ss), new Ss(), new Ss(new S()) };
  1924. Ss?[] result = new Ss?[size];
  1925. for (int i = 0; i < size; i++) {
  1926. result[i] = vals[i % vals.Length];
  1927. }
  1928. return result;
  1929. }
  1930. static bool check_Ssq_ArrayIndex(Ss?[] val) {
  1931. bool success = checkEx_Ssq_ArrayIndex(val, -1);
  1932. for (int i = 0; i < val.Length; i++) {
  1933. success &= check_Ssq_ArrayIndex(val, 0);
  1934. }
  1935. success &= checkEx_Ssq_ArrayIndex(val, val.Length);
  1936. return success;
  1937. }
  1938. static bool checkEx_Ssq_ArrayIndex(Ss?[] val, int index) {
  1939. try {
  1940. check_Ssq_ArrayIndex(val, index);
  1941. Console.WriteLine("Ssq_ArrayIndex[" + index + "] failed");
  1942. return false;
  1943. }
  1944. catch {
  1945. return true;
  1946. }
  1947. }
  1948. static bool check_Ssq_ArrayIndex(Ss?[] val, int index) {
  1949. Expression<Func<Ss?>> e =
  1950. Expression.Lambda<Func<Ss?>>(
  1951. Expression.ArrayIndex(Expression.Constant(val, typeof(Ss?[])),
  1952. Expression.Constant(index, typeof(int))),
  1953. new System.Collections.Generic.List<ParameterExpression>());
  1954. Func<Ss?> f = e.Compile();
  1955. return object.Equals(f(), val[index]);
  1956. }
  1957. }
  1958. public static class Ext {
  1959. public static void StartCapture() {
  1960. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1961. // m.Invoke(null, new object[] { "test.dll" });
  1962. }
  1963. public static void StopCapture() {
  1964. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1965. // m.Invoke(null, new object[0]);
  1966. }
  1967. public static bool IsIntegralOrEnum(Type type) {
  1968. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1969. case TypeCode.Byte:
  1970. case TypeCode.SByte:
  1971. case TypeCode.Int16:
  1972. case TypeCode.Int32:
  1973. case TypeCode.Int64:
  1974. case TypeCode.UInt16:
  1975. case TypeCode.UInt32:
  1976. case TypeCode.UInt64:
  1977. return true;
  1978. default:
  1979. return false;
  1980. }
  1981. }
  1982. public static bool IsFloating(Type type) {
  1983. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1984. case TypeCode.Single:
  1985. case TypeCode.Double:
  1986. return true;
  1987. default:
  1988. return false;
  1989. }
  1990. }
  1991. public static Type GetNonNullableType(Type type) {
  1992. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1993. type.GetGenericArguments()[0] :
  1994. type;
  1995. }
  1996. }
  1997. interface I {
  1998. void M();
  1999. }
  2000. public class C : IEquatable<C>, I {
  2001. void I.M() {
  2002. }
  2003. public override bool Equals(object o) {
  2004. return o is C && Equals((C) o);
  2005. }
  2006. public bool Equals(C c) {
  2007. return c != null;
  2008. }
  2009. public override int GetHashCode() {
  2010. return 0;
  2011. }
  2012. }
  2013. public class D : C, IEquatable<D> {
  2014. public int Val;
  2015. public D() {
  2016. }
  2017. public D(int val) {
  2018. Val = val;
  2019. }
  2020. public override bool Equals(object o) {
  2021. return o is D && Equals((D) o);
  2022. }
  2023. public bool Equals(D d) {
  2024. return d != null && d.Val == Val;
  2025. }
  2026. public override int GetHashCode() {
  2027. return Val;
  2028. }
  2029. }
  2030. public enum E {
  2031. A=1, B=2
  2032. }
  2033. public enum El : long {
  2034. A, B, C
  2035. }
  2036. public struct S : IEquatable<S> {
  2037. public override bool Equals(object o) {
  2038. return (o is S) && Equals((S) o);
  2039. }
  2040. public bool Equals(S other) {
  2041. return true;
  2042. }
  2043. public override int GetHashCode() {
  2044. return 0;
  2045. }
  2046. }
  2047. public struct Sp : IEquatable<Sp> {
  2048. public Sp(int i, double d) {
  2049. I = i;
  2050. D = d;
  2051. }
  2052. public int I;
  2053. public double D;
  2054. public override bool Equals(object o) {
  2055. return (o is Sp) && Equals((Sp) o);
  2056. }
  2057. public bool Equals(Sp other) {
  2058. return other.I == I && other.D == D;
  2059. }
  2060. public override int GetHashCode() {
  2061. return I.GetHashCode() ^ D.GetHashCode();
  2062. }
  2063. }
  2064. public struct Ss : IEquatable<Ss> {
  2065. public Ss(S s) {
  2066. Val = s;
  2067. }
  2068. public S Val;
  2069. public override bool Equals(object o) {
  2070. return (o is Ss) && Equals((Ss) o);
  2071. }
  2072. public bool Equals(Ss other) {
  2073. return other.Val.Equals(Val);
  2074. }
  2075. public override int GetHashCode() {
  2076. return Val.GetHashCode();
  2077. }
  2078. }
  2079. public struct Sc : IEquatable<Sc> {
  2080. public Sc(string s) {
  2081. S = s;
  2082. }
  2083. public string S;
  2084. public override bool Equals(object o) {
  2085. return (o is Sc) && Equals((Sc) o);
  2086. }
  2087. public bool Equals(Sc other) {
  2088. return other.S == S;
  2089. }
  2090. public override int GetHashCode() {
  2091. return S.GetHashCode();
  2092. }
  2093. }
  2094. public struct Scs : IEquatable<Scs> {
  2095. public Scs(string s, S val) {
  2096. S = s;
  2097. Val = val;
  2098. }
  2099. public string S;
  2100. public S Val;
  2101. public override bool Equals(object o) {
  2102. return (o is Scs) && Equals((Scs) o);
  2103. }
  2104. public bool Equals(Scs other) {
  2105. return other.S == S && other.Val.Equals(Val);
  2106. }
  2107. public override int GetHashCode() {
  2108. return S.GetHashCode() ^ Val.GetHashCode();
  2109. }
  2110. }
  2111. }
  2112. //-------- Scenario 3183
  2113. namespace Scenario3183{
  2114. public class Test
  2115. {
  2116. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Scq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  2117. public static Expression Scq_ArrayIndex__() {
  2118. if(Main() != 0 ) {
  2119. throw new Exception();
  2120. } else {
  2121. return Expression.Constant(0);
  2122. }
  2123. }
  2124. public static int Main()
  2125. {
  2126. Ext.StartCapture();
  2127. bool success = false;
  2128. try
  2129. {
  2130. success = check_Scq_ArrayIndex();
  2131. }
  2132. finally
  2133. {
  2134. Ext.StopCapture();
  2135. }
  2136. return success ? 0 : 1;
  2137. }
  2138. static bool check_Scq_ArrayIndex() {
  2139. return checkEx_Scq_ArrayIndex(null, -1) &
  2140. checkEx_Scq_ArrayIndex(null, 0) &
  2141. checkEx_Scq_ArrayIndex(null, 1) &
  2142. check_Scq_ArrayIndex(genArrScq_ArrayIndex(0)) &
  2143. check_Scq_ArrayIndex(genArrScq_ArrayIndex(1)) &
  2144. check_Scq_ArrayIndex(genArrScq_ArrayIndex(5));
  2145. }
  2146. static Sc?[] genArrScq_ArrayIndex(int size) {
  2147. Sc?[] vals = new Sc?[] { default(Sc), new Sc(), new Sc(null) };
  2148. Sc?[] result = new Sc?[size];
  2149. for (int i = 0; i < size; i++) {
  2150. result[i] = vals[i % vals.Length];
  2151. }
  2152. return result;
  2153. }
  2154. static bool check_Scq_ArrayIndex(Sc?[] val) {
  2155. bool success = checkEx_Scq_ArrayIndex(val, -1);
  2156. for (int i = 0; i < val.Length; i++) {
  2157. success &= check_Scq_ArrayIndex(val, 0);
  2158. }
  2159. success &= checkEx_Scq_ArrayIndex(val, val.Length);
  2160. return success;
  2161. }
  2162. static bool checkEx_Scq_ArrayIndex(Sc?[] val, int index) {
  2163. try {
  2164. check_Scq_ArrayIndex(val, index);
  2165. Console.WriteLine("Scq_ArrayIndex[" + index + "] failed");
  2166. return false;
  2167. }
  2168. catch {
  2169. return true;
  2170. }
  2171. }
  2172. static bool check_Scq_ArrayIndex(Sc?[] val, int index) {
  2173. Expression<Func<Sc?>> e =
  2174. Expression.Lambda<Func<Sc?>>(
  2175. Expression.ArrayIndex(Expression.Constant(val, typeof(Sc?[])),
  2176. Expression.Constant(index, typeof(int))),
  2177. new System.Collections.Generic.List<ParameterExpression>());
  2178. Func<Sc?> f = e.Compile();
  2179. return object.Equals(f(), val[index]);
  2180. }
  2181. }
  2182. public static class Ext {
  2183. public static void StartCapture() {
  2184. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2185. // m.Invoke(null, new object[] { "test.dll" });
  2186. }
  2187. public static void StopCapture() {
  2188. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2189. // m.Invoke(null, new object[0]);
  2190. }
  2191. public static bool IsIntegralOrEnum(Type type) {
  2192. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2193. case TypeCode.Byte:
  2194. case TypeCode.SByte:
  2195. case TypeCode.Int16:
  2196. case TypeCode.Int32:
  2197. case TypeCode.Int64:
  2198. case TypeCode.UInt16:
  2199. case TypeCode.UInt32:
  2200. case TypeCode.UInt64:
  2201. return true;
  2202. default:
  2203. return false;
  2204. }
  2205. }
  2206. public static bool IsFloating(Type type) {
  2207. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2208. case TypeCode.Single:
  2209. case TypeCode.Double:
  2210. return true;
  2211. default:
  2212. return false;
  2213. }
  2214. }
  2215. public static Type GetNonNullableType(Type type) {
  2216. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  2217. type.GetGenericArguments()[0] :
  2218. type;
  2219. }
  2220. }
  2221. interface I {
  2222. void M();
  2223. }
  2224. public class C : IEquatable<C>, I {
  2225. void I.M() {
  2226. }
  2227. public override bool Equals(object o) {
  2228. return o is C && Equals((C) o);
  2229. }
  2230. public bool Equals(C c) {
  2231. return c != null;
  2232. }
  2233. public override int GetHashCode() {
  2234. return 0;
  2235. }
  2236. }
  2237. public class D : C, IEquatable<D> {
  2238. public int Val;
  2239. public D() {
  2240. }
  2241. public D(int val) {
  2242. Val = val;
  2243. }
  2244. public override bool Equals(object o) {
  2245. return o is D && Equals((D) o);
  2246. }
  2247. public bool Equals(D d) {
  2248. return d != null && d.Val == Val;
  2249. }
  2250. public override int GetHashCode() {
  2251. return Val;
  2252. }
  2253. }
  2254. public enum E {
  2255. A=1, B=2
  2256. }
  2257. public enum El : long {
  2258. A, B, C
  2259. }
  2260. public struct S : IEquatable<S> {
  2261. public override bool Equals(object o) {
  2262. return (o is S) && Equals((S) o);
  2263. }
  2264. public bool Equals(S other) {
  2265. return true;
  2266. }
  2267. public override int GetHashCode() {
  2268. return 0;
  2269. }
  2270. }
  2271. public struct Sp : IEquatable<Sp> {
  2272. public Sp(int i, double d) {
  2273. I = i;
  2274. D = d;
  2275. }
  2276. public int I;
  2277. public double D;
  2278. public override bool Equals(object o) {
  2279. return (o is Sp) && Equals((Sp) o);
  2280. }
  2281. public bool Equals(Sp other) {
  2282. return other.I == I && other.D == D;
  2283. }
  2284. public override int GetHashCode() {
  2285. return I.GetHashCode() ^ D.GetHashCode();
  2286. }
  2287. }
  2288. public struct Ss : IEquatable<Ss> {
  2289. public Ss(S s) {
  2290. Val = s;
  2291. }
  2292. public S Val;
  2293. public override bool Equals(object o) {
  2294. return (o is Ss) && Equals((Ss) o);
  2295. }
  2296. public bool Equals(Ss other) {
  2297. return other.Val.Equals(Val);
  2298. }
  2299. public override int GetHashCode() {
  2300. return Val.GetHashCode();
  2301. }
  2302. }
  2303. public struct Sc : IEquatable<Sc> {
  2304. public Sc(string s) {
  2305. S = s;
  2306. }
  2307. public string S;
  2308. public override bool Equals(object o) {
  2309. return (o is Sc) && Equals((Sc) o);
  2310. }
  2311. public bool Equals(Sc other) {
  2312. return other.S == S;
  2313. }
  2314. public override int GetHashCode() {
  2315. return S.GetHashCode();
  2316. }
  2317. }
  2318. public struct Scs : IEquatable<Scs> {
  2319. public Scs(string s, S val) {
  2320. S = s;
  2321. Val = val;
  2322. }
  2323. public string S;
  2324. public S Val;
  2325. public override bool Equals(object o) {
  2326. return (o is Scs) && Equals((Scs) o);
  2327. }
  2328. public bool Equals(Scs other) {
  2329. return other.S == S && other.Val.Equals(Val);
  2330. }
  2331. public override int GetHashCode() {
  2332. return S.GetHashCode() ^ Val.GetHashCode();
  2333. }
  2334. }
  2335. }
  2336. //-------- Scenario 3184
  2337. namespace Scenario3184{
  2338. public class Test
  2339. {
  2340. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Scsq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  2341. public static Expression Scsq_ArrayIndex__() {
  2342. if(Main() != 0 ) {
  2343. throw new Exception();
  2344. } else {
  2345. return Expression.Constant(0);
  2346. }
  2347. }
  2348. public static int Main()
  2349. {
  2350. Ext.StartCapture();
  2351. bool success = false;
  2352. try
  2353. {
  2354. success = check_Scsq_ArrayIndex();
  2355. }
  2356. finally
  2357. {
  2358. Ext.StopCapture();
  2359. }
  2360. return success ? 0 : 1;
  2361. }
  2362. static bool check_Scsq_ArrayIndex() {
  2363. return checkEx_Scsq_ArrayIndex(null, -1) &
  2364. checkEx_Scsq_ArrayIndex(null, 0) &
  2365. checkEx_Scsq_ArrayIndex(null, 1) &
  2366. check_Scsq_ArrayIndex(genArrScsq_ArrayIndex(0)) &
  2367. check_Scsq_ArrayIndex(genArrScsq_ArrayIndex(1)) &
  2368. check_Scsq_ArrayIndex(genArrScsq_ArrayIndex(5));
  2369. }
  2370. static Scs?[] genArrScsq_ArrayIndex(int size) {
  2371. Scs?[] vals = new Scs?[] { default(Scs), new Scs(), new Scs(null,new S()) };
  2372. Scs?[] result = new Scs?[size];
  2373. for (int i = 0; i < size; i++) {
  2374. result[i] = vals[i % vals.Length];
  2375. }
  2376. return result;
  2377. }
  2378. static bool check_Scsq_ArrayIndex(Scs?[] val) {
  2379. bool success = checkEx_Scsq_ArrayIndex(val, -1);
  2380. for (int i = 0; i < val.Length; i++) {
  2381. success &= check_Scsq_ArrayIndex(val, 0);
  2382. }
  2383. success &= checkEx_Scsq_ArrayIndex(val, val.Length);
  2384. return success;
  2385. }
  2386. static bool checkEx_Scsq_ArrayIndex(Scs?[] val, int index) {
  2387. try {
  2388. check_Scsq_ArrayIndex(val, index);
  2389. Console.WriteLine("Scsq_ArrayIndex[" + index + "] failed");
  2390. return false;
  2391. }
  2392. catch {
  2393. return true;
  2394. }
  2395. }
  2396. static bool check_Scsq_ArrayIndex(Scs?[] val, int index) {
  2397. Expression<Func<Scs?>> e =
  2398. Expression.Lambda<Func<Scs?>>(
  2399. Expression.ArrayIndex(Expression.Constant(val, typeof(Scs?[])),
  2400. Expression.Constant(index, typeof(int))),
  2401. new System.Collections.Generic.List<ParameterExpression>());
  2402. Func<Scs?> f = e.Compile();
  2403. return object.Equals(f(), val[index]);
  2404. }
  2405. }
  2406. public static class Ext {
  2407. public static void StartCapture() {
  2408. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2409. // m.Invoke(null, new object[] { "test.dll" });
  2410. }
  2411. public static void StopCapture() {
  2412. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2413. // m.Invoke(null, new object[0]);
  2414. }
  2415. public static bool IsIntegralOrEnum(Type type) {
  2416. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2417. case TypeCode.Byte:
  2418. case TypeCode.SByte:
  2419. case TypeCode.Int16:
  2420. case TypeCode.Int32:
  2421. case TypeCode.Int64:
  2422. case TypeCode.UInt16:
  2423. case TypeCode.UInt32:
  2424. case TypeCode.UInt64:
  2425. return true;
  2426. default:
  2427. return false;
  2428. }
  2429. }
  2430. public static bool IsFloating(Type type) {
  2431. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2432. case TypeCode.Single:
  2433. case TypeCode.Double:
  2434. return true;
  2435. default:
  2436. return false;
  2437. }
  2438. }
  2439. public static Type GetNonNullableType(Type type) {
  2440. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  2441. type.GetGenericArguments()[0] :
  2442. type;
  2443. }
  2444. }
  2445. interface I {
  2446. void M();
  2447. }
  2448. public class C : IEquatable<C>, I {
  2449. void I.M() {
  2450. }
  2451. public override bool Equals(object o) {
  2452. return o is C && Equals((C) o);
  2453. }
  2454. public bool Equals(C c) {
  2455. return c != null;
  2456. }
  2457. public override int GetHashCode() {
  2458. return 0;
  2459. }
  2460. }
  2461. public class D : C, IEquatable<D> {
  2462. public int Val;
  2463. public D() {
  2464. }
  2465. public D(int val) {
  2466. Val = val;
  2467. }
  2468. public override bool Equals(object o) {
  2469. return o is D && Equals((D) o);
  2470. }
  2471. public bool Equals(D d) {
  2472. return d != null && d.Val == Val;
  2473. }
  2474. public override int GetHashCode() {
  2475. return Val;
  2476. }
  2477. }
  2478. public enum E {
  2479. A=1, B=2
  2480. }
  2481. public enum El : long {
  2482. A, B, C
  2483. }
  2484. public struct S : IEquatable<S> {
  2485. public override bool Equals(object o) {
  2486. return (o is S) && Equals((S) o);
  2487. }
  2488. public bool Equals(S other) {
  2489. return true;
  2490. }
  2491. public override int GetHashCode() {
  2492. return 0;
  2493. }
  2494. }
  2495. public struct Sp : IEquatable<Sp> {
  2496. public Sp(int i, double d) {
  2497. I = i;
  2498. D = d;
  2499. }
  2500. public int I;
  2501. public double D;
  2502. public override bool Equals(object o) {
  2503. return (o is Sp) && Equals((Sp) o);
  2504. }
  2505. public bool Equals(Sp other) {
  2506. return other.I == I && other.D == D;
  2507. }
  2508. public override int GetHashCode() {
  2509. return I.GetHashCode() ^ D.GetHashCode();
  2510. }
  2511. }
  2512. public struct Ss : IEquatable<Ss> {
  2513. public Ss(S s) {
  2514. Val = s;
  2515. }
  2516. public S Val;
  2517. public override bool Equals(object o) {
  2518. return (o is Ss) && Equals((Ss) o);
  2519. }
  2520. public bool Equals(Ss other) {
  2521. return other.Val.Equals(Val);
  2522. }
  2523. public override int GetHashCode() {
  2524. return Val.GetHashCode();
  2525. }
  2526. }
  2527. public struct Sc : IEquatable<Sc> {
  2528. public Sc(string s) {
  2529. S = s;
  2530. }
  2531. public string S;
  2532. public override bool Equals(object o) {
  2533. return (o is Sc) && Equals((Sc) o);
  2534. }
  2535. public bool Equals(Sc other) {
  2536. return other.S == S;
  2537. }
  2538. public override int GetHashCode() {
  2539. return S.GetHashCode();
  2540. }
  2541. }
  2542. public struct Scs : IEquatable<Scs> {
  2543. public Scs(string s, S val) {
  2544. S = s;
  2545. Val = val;
  2546. }
  2547. public string S;
  2548. public S Val;
  2549. public override bool Equals(object o) {
  2550. return (o is Scs) && Equals((Scs) o);
  2551. }
  2552. public bool Equals(Scs other) {
  2553. return other.S == S && other.Val.Equals(Val);
  2554. }
  2555. public override int GetHashCode() {
  2556. return S.GetHashCode() ^ Val.GetHashCode();
  2557. }
  2558. }
  2559. }
  2560. //-------- Scenario 3185
  2561. namespace Scenario3185{
  2562. public class Test
  2563. {
  2564. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Tsq_ArrayIndex_S___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  2565. public static Expression Tsq_ArrayIndex_S___() {
  2566. if(Main() != 0 ) {
  2567. throw new Exception();
  2568. } else {
  2569. return Expression.Constant(0);
  2570. }
  2571. }
  2572. public static int Main()
  2573. {
  2574. Ext.StartCapture();
  2575. bool success = false;
  2576. try
  2577. {
  2578. success = check_Tsq_ArrayIndex<S>();
  2579. }
  2580. finally
  2581. {
  2582. Ext.StopCapture();
  2583. }
  2584. return success ? 0 : 1;
  2585. }
  2586. static bool check_Tsq_ArrayIndex<Ts>() where Ts : struct {
  2587. return checkEx_Tsq_ArrayIndex<Ts>(null, -1) &
  2588. checkEx_Tsq_ArrayIndex<Ts>(null, 0) &
  2589. checkEx_Tsq_ArrayIndex<Ts>(null, 1) &
  2590. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(0)) &
  2591. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(1)) &
  2592. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(5));
  2593. }
  2594. static Ts?[] genArrTsq_ArrayIndex<Ts>(int size) where Ts : struct {
  2595. Ts?[] vals = new Ts?[] { default(Ts), new Ts() };
  2596. Ts?[] result = new Ts?[size];
  2597. for (int i = 0; i < size; i++) {
  2598. result[i] = vals[i % vals.Length];
  2599. }
  2600. return result;
  2601. }
  2602. static bool check_Tsq_ArrayIndex<Ts>(Ts?[] val) where Ts : struct {
  2603. bool success = checkEx_Tsq_ArrayIndex<Ts>(val, -1);
  2604. for (int i = 0; i < val.Length; i++) {
  2605. success &= check_Tsq_ArrayIndex<Ts>(val, 0);
  2606. }
  2607. success &= checkEx_Tsq_ArrayIndex<Ts>(val, val.Length);
  2608. return success;
  2609. }
  2610. static bool checkEx_Tsq_ArrayIndex<Ts>(Ts?[] val, int index) where Ts : struct {
  2611. try {
  2612. check_Tsq_ArrayIndex<Ts>(val, index);
  2613. Console.WriteLine("Tsq_ArrayIndex[" + index + "] failed");
  2614. return false;
  2615. }
  2616. catch {
  2617. return true;
  2618. }
  2619. }
  2620. static bool check_Tsq_ArrayIndex<Ts>(Ts?[] val, int index) where Ts : struct {
  2621. Expression<Func<Ts?>> e =
  2622. Expression.Lambda<Func<Ts?>>(
  2623. Expression.ArrayIndex(Expression.Constant(val, typeof(Ts?[])),
  2624. Expression.Constant(index, typeof(int))),
  2625. new System.Collections.Generic.List<ParameterExpression>());
  2626. Func<Ts?> f = e.Compile();
  2627. return object.Equals(f(), val[index]);
  2628. }
  2629. }
  2630. public static class Ext {
  2631. public static void StartCapture() {
  2632. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2633. // m.Invoke(null, new object[] { "test.dll" });
  2634. }
  2635. public static void StopCapture() {
  2636. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2637. // m.Invoke(null, new object[0]);
  2638. }
  2639. public static bool IsIntegralOrEnum(Type type) {
  2640. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2641. case TypeCode.Byte:
  2642. case TypeCode.SByte:
  2643. case TypeCode.Int16:
  2644. case TypeCode.Int32:
  2645. case TypeCode.Int64:
  2646. case TypeCode.UInt16:
  2647. case TypeCode.UInt32:
  2648. case TypeCode.UInt64:
  2649. return true;
  2650. default:
  2651. return false;
  2652. }
  2653. }
  2654. public static bool IsFloating(Type type) {
  2655. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2656. case TypeCode.Single:
  2657. case TypeCode.Double:
  2658. return true;
  2659. default:
  2660. return false;
  2661. }
  2662. }
  2663. public static Type GetNonNullableType(Type type) {
  2664. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  2665. type.GetGenericArguments()[0] :
  2666. type;
  2667. }
  2668. }
  2669. interface I {
  2670. void M();
  2671. }
  2672. public class C : IEquatable<C>, I {
  2673. void I.M() {
  2674. }
  2675. public override bool Equals(object o) {
  2676. return o is C && Equals((C) o);
  2677. }
  2678. public bool Equals(C c) {
  2679. return c != null;
  2680. }
  2681. public override int GetHashCode() {
  2682. return 0;
  2683. }
  2684. }
  2685. public class D : C, IEquatable<D> {
  2686. public int Val;
  2687. public D() {
  2688. }
  2689. public D(int val) {
  2690. Val = val;
  2691. }
  2692. public override bool Equals(object o) {
  2693. return o is D && Equals((D) o);
  2694. }
  2695. public bool Equals(D d) {
  2696. return d != null && d.Val == Val;
  2697. }
  2698. public override int GetHashCode() {
  2699. return Val;
  2700. }
  2701. }
  2702. public enum E {
  2703. A=1, B=2
  2704. }
  2705. public enum El : long {
  2706. A, B, C
  2707. }
  2708. public struct S : IEquatable<S> {
  2709. public override bool Equals(object o) {
  2710. return (o is S) && Equals((S) o);
  2711. }
  2712. public bool Equals(S other) {
  2713. return true;
  2714. }
  2715. public override int GetHashCode() {
  2716. return 0;
  2717. }
  2718. }
  2719. public struct Sp : IEquatable<Sp> {
  2720. public Sp(int i, double d) {
  2721. I = i;
  2722. D = d;
  2723. }
  2724. public int I;
  2725. public double D;
  2726. public override bool Equals(object o) {
  2727. return (o is Sp) && Equals((Sp) o);
  2728. }
  2729. public bool Equals(Sp other) {
  2730. return other.I == I && other.D == D;
  2731. }
  2732. public override int GetHashCode() {
  2733. return I.GetHashCode() ^ D.GetHashCode();
  2734. }
  2735. }
  2736. public struct Ss : IEquatable<Ss> {
  2737. public Ss(S s) {
  2738. Val = s;
  2739. }
  2740. public S Val;
  2741. public override bool Equals(object o) {
  2742. return (o is Ss) && Equals((Ss) o);
  2743. }
  2744. public bool Equals(Ss other) {
  2745. return other.Val.Equals(Val);
  2746. }
  2747. public override int GetHashCode() {
  2748. return Val.GetHashCode();
  2749. }
  2750. }
  2751. public struct Sc : IEquatable<Sc> {
  2752. public Sc(string s) {
  2753. S = s;
  2754. }
  2755. public string S;
  2756. public override bool Equals(object o) {
  2757. return (o is Sc) && Equals((Sc) o);
  2758. }
  2759. public bool Equals(Sc other) {
  2760. return other.S == S;
  2761. }
  2762. public override int GetHashCode() {
  2763. return S.GetHashCode();
  2764. }
  2765. }
  2766. public struct Scs : IEquatable<Scs> {
  2767. public Scs(string s, S val) {
  2768. S = s;
  2769. Val = val;
  2770. }
  2771. public string S;
  2772. public S Val;
  2773. public override bool Equals(object o) {
  2774. return (o is Scs) && Equals((Scs) o);
  2775. }
  2776. public bool Equals(Scs other) {
  2777. return other.S == S && other.Val.Equals(Val);
  2778. }
  2779. public override int GetHashCode() {
  2780. return S.GetHashCode() ^ Val.GetHashCode();
  2781. }
  2782. }
  2783. }
  2784. //-------- Scenario 3186
  2785. namespace Scenario3186{
  2786. public class Test
  2787. {
  2788. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Tsq_ArrayIndex_Scs___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  2789. public static Expression Tsq_ArrayIndex_Scs___() {
  2790. if(Main() != 0 ) {
  2791. throw new Exception();
  2792. } else {
  2793. return Expression.Constant(0);
  2794. }
  2795. }
  2796. public static int Main()
  2797. {
  2798. Ext.StartCapture();
  2799. bool success = false;
  2800. try
  2801. {
  2802. success = check_Tsq_ArrayIndex<Scs>();
  2803. }
  2804. finally
  2805. {
  2806. Ext.StopCapture();
  2807. }
  2808. return success ? 0 : 1;
  2809. }
  2810. static bool check_Tsq_ArrayIndex<Ts>() where Ts : struct {
  2811. return checkEx_Tsq_ArrayIndex<Ts>(null, -1) &
  2812. checkEx_Tsq_ArrayIndex<Ts>(null, 0) &
  2813. checkEx_Tsq_ArrayIndex<Ts>(null, 1) &
  2814. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(0)) &
  2815. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(1)) &
  2816. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(5));
  2817. }
  2818. static Ts?[] genArrTsq_ArrayIndex<Ts>(int size) where Ts : struct {
  2819. Ts?[] vals = new Ts?[] { default(Ts), new Ts() };
  2820. Ts?[] result = new Ts?[size];
  2821. for (int i = 0; i < size; i++) {
  2822. result[i] = vals[i % vals.Length];
  2823. }
  2824. return result;
  2825. }
  2826. static bool check_Tsq_ArrayIndex<Ts>(Ts?[] val) where Ts : struct {
  2827. bool success = checkEx_Tsq_ArrayIndex<Ts>(val, -1);
  2828. for (int i = 0; i < val.Length; i++) {
  2829. success &= check_Tsq_ArrayIndex<Ts>(val, 0);
  2830. }
  2831. success &= checkEx_Tsq_ArrayIndex<Ts>(val, val.Length);
  2832. return success;
  2833. }
  2834. static bool checkEx_Tsq_ArrayIndex<Ts>(Ts?[] val, int index) where Ts : struct {
  2835. try {
  2836. check_Tsq_ArrayIndex<Ts>(val, index);
  2837. Console.WriteLine("Tsq_ArrayIndex[" + index + "] failed");
  2838. return false;
  2839. }
  2840. catch {
  2841. return true;
  2842. }
  2843. }
  2844. static bool check_Tsq_ArrayIndex<Ts>(Ts?[] val, int index) where Ts : struct {
  2845. Expression<Func<Ts?>> e =
  2846. Expression.Lambda<Func<Ts?>>(
  2847. Expression.ArrayIndex(Expression.Constant(val, typeof(Ts?[])),
  2848. Expression.Constant(index, typeof(int))),
  2849. new System.Collections.Generic.List<ParameterExpression>());
  2850. Func<Ts?> f = e.Compile();
  2851. return object.Equals(f(), val[index]);
  2852. }
  2853. }
  2854. public static class Ext {
  2855. public static void StartCapture() {
  2856. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2857. // m.Invoke(null, new object[] { "test.dll" });
  2858. }
  2859. public static void StopCapture() {
  2860. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  2861. // m.Invoke(null, new object[0]);
  2862. }
  2863. public static bool IsIntegralOrEnum(Type type) {
  2864. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2865. case TypeCode.Byte:
  2866. case TypeCode.SByte:
  2867. case TypeCode.Int16:
  2868. case TypeCode.Int32:
  2869. case TypeCode.Int64:
  2870. case TypeCode.UInt16:
  2871. case TypeCode.UInt32:
  2872. case TypeCode.UInt64:
  2873. return true;
  2874. default:
  2875. return false;
  2876. }
  2877. }
  2878. public static bool IsFloating(Type type) {
  2879. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  2880. case TypeCode.Single:
  2881. case TypeCode.Double:
  2882. return true;
  2883. default:
  2884. return false;
  2885. }
  2886. }
  2887. public static Type GetNonNullableType(Type type) {
  2888. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  2889. type.GetGenericArguments()[0] :
  2890. type;
  2891. }
  2892. }
  2893. interface I {
  2894. void M();
  2895. }
  2896. public class C : IEquatable<C>, I {
  2897. void I.M() {
  2898. }
  2899. public override bool Equals(object o) {
  2900. return o is C && Equals((C) o);
  2901. }
  2902. public bool Equals(C c) {
  2903. return c != null;
  2904. }
  2905. public override int GetHashCode() {
  2906. return 0;
  2907. }
  2908. }
  2909. public class D : C, IEquatable<D> {
  2910. public int Val;
  2911. public D() {
  2912. }
  2913. public D(int val) {
  2914. Val = val;
  2915. }
  2916. public override bool Equals(object o) {
  2917. return o is D && Equals((D) o);
  2918. }
  2919. public bool Equals(D d) {
  2920. return d != null && d.Val == Val;
  2921. }
  2922. public override int GetHashCode() {
  2923. return Val;
  2924. }
  2925. }
  2926. public enum E {
  2927. A=1, B=2
  2928. }
  2929. public enum El : long {
  2930. A, B, C
  2931. }
  2932. public struct S : IEquatable<S> {
  2933. public override bool Equals(object o) {
  2934. return (o is S) && Equals((S) o);
  2935. }
  2936. public bool Equals(S other) {
  2937. return true;
  2938. }
  2939. public override int GetHashCode() {
  2940. return 0;
  2941. }
  2942. }
  2943. public struct Sp : IEquatable<Sp> {
  2944. public Sp(int i, double d) {
  2945. I = i;
  2946. D = d;
  2947. }
  2948. public int I;
  2949. public double D;
  2950. public override bool Equals(object o) {
  2951. return (o is Sp) && Equals((Sp) o);
  2952. }
  2953. public bool Equals(Sp other) {
  2954. return other.I == I && other.D == D;
  2955. }
  2956. public override int GetHashCode() {
  2957. return I.GetHashCode() ^ D.GetHashCode();
  2958. }
  2959. }
  2960. public struct Ss : IEquatable<Ss> {
  2961. public Ss(S s) {
  2962. Val = s;
  2963. }
  2964. public S Val;
  2965. public override bool Equals(object o) {
  2966. return (o is Ss) && Equals((Ss) o);
  2967. }
  2968. public bool Equals(Ss other) {
  2969. return other.Val.Equals(Val);
  2970. }
  2971. public override int GetHashCode() {
  2972. return Val.GetHashCode();
  2973. }
  2974. }
  2975. public struct Sc : IEquatable<Sc> {
  2976. public Sc(string s) {
  2977. S = s;
  2978. }
  2979. public string S;
  2980. public override bool Equals(object o) {
  2981. return (o is Sc) && Equals((Sc) o);
  2982. }
  2983. public bool Equals(Sc other) {
  2984. return other.S == S;
  2985. }
  2986. public override int GetHashCode() {
  2987. return S.GetHashCode();
  2988. }
  2989. }
  2990. public struct Scs : IEquatable<Scs> {
  2991. public Scs(string s, S val) {
  2992. S = s;
  2993. Val = val;
  2994. }
  2995. public string S;
  2996. public S Val;
  2997. public override bool Equals(object o) {
  2998. return (o is Scs) && Equals((Scs) o);
  2999. }
  3000. public bool Equals(Scs other) {
  3001. return other.S == S && other.Val.Equals(Val);
  3002. }
  3003. public override int GetHashCode() {
  3004. return S.GetHashCode() ^ Val.GetHashCode();
  3005. }
  3006. }
  3007. }
  3008. //-------- Scenario 3187
  3009. namespace Scenario3187{
  3010. public class Test
  3011. {
  3012. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Tsq_ArrayIndex_E___", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  3013. public static Expression Tsq_ArrayIndex_E___() {
  3014. if(Main() != 0 ) {
  3015. throw new Exception();
  3016. } else {
  3017. return Expression.Constant(0);
  3018. }
  3019. }
  3020. public static int Main()
  3021. {
  3022. Ext.StartCapture();
  3023. bool success = false;
  3024. try
  3025. {
  3026. success = check_Tsq_ArrayIndex<E>();
  3027. }
  3028. finally
  3029. {
  3030. Ext.StopCapture();
  3031. }
  3032. return success ? 0 : 1;
  3033. }
  3034. static bool check_Tsq_ArrayIndex<Ts>() where Ts : struct {
  3035. return checkEx_Tsq_ArrayIndex<Ts>(null, -1) &
  3036. checkEx_Tsq_ArrayIndex<Ts>(null, 0) &
  3037. checkEx_Tsq_ArrayIndex<Ts>(null, 1) &
  3038. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(0)) &
  3039. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(1)) &
  3040. check_Tsq_ArrayIndex<Ts>(genArrTsq_ArrayIndex<Ts>(5));
  3041. }
  3042. static Ts?[] genArrTsq_ArrayIndex<Ts>(int size) where Ts : struct {
  3043. Ts?[] vals = new Ts?[] { default(Ts), new Ts() };
  3044. Ts?[] result = new Ts?[size];
  3045. for (int i = 0; i < size; i++) {
  3046. result[i] = vals[i % vals.Length];
  3047. }
  3048. return result;
  3049. }
  3050. static bool check_Tsq_ArrayIndex<Ts>(Ts?[] val) where Ts : struct {
  3051. bool success = checkEx_Tsq_ArrayIndex<Ts>(val, -1);
  3052. for (int i = 0; i < val.Length; i++) {
  3053. success &= check_Tsq_ArrayIndex<Ts>(val, 0);
  3054. }
  3055. success &= checkEx_Tsq_ArrayIndex<Ts>(val, val.Length);
  3056. return success;
  3057. }
  3058. static bool checkEx_Tsq_ArrayIndex<Ts>(Ts?[] val, int index) where Ts : struct {
  3059. try {
  3060. check_Tsq_ArrayIndex<Ts>(val, index);
  3061. Console.WriteLine("Tsq_ArrayIndex[" + index + "] failed");
  3062. return false;
  3063. }
  3064. catch {
  3065. return true;
  3066. }
  3067. }
  3068. static bool check_Tsq_ArrayIndex<Ts>(Ts?[] val, int index) where Ts : struct {
  3069. Expression<Func<Ts?>> e =
  3070. Expression.Lambda<Func<Ts?>>(
  3071. Expression.ArrayIndex(Expression.Constant(val, typeof(Ts?[])),
  3072. Expression.Constant(index, typeof(int))),
  3073. new System.Collections.Generic.List<ParameterExpression>());
  3074. Func<Ts?> f = e.Compile();
  3075. return object.Equals(f(), val[index]);
  3076. }
  3077. }
  3078. public static class Ext {
  3079. public static void StartCapture() {
  3080. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3081. // m.Invoke(null, new object[] { "test.dll" });
  3082. }
  3083. public static void StopCapture() {
  3084. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3085. // m.Invoke(null, new object[0]);
  3086. }
  3087. public static bool IsIntegralOrEnum(Type type) {
  3088. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3089. case TypeCode.Byte:
  3090. case TypeCode.SByte:
  3091. case TypeCode.Int16:
  3092. case TypeCode.Int32:
  3093. case TypeCode.Int64:
  3094. case TypeCode.UInt16:
  3095. case TypeCode.UInt32:
  3096. case TypeCode.UInt64:
  3097. return true;
  3098. default:
  3099. return false;
  3100. }
  3101. }
  3102. public static bool IsFloating(Type type) {
  3103. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3104. case TypeCode.Single:
  3105. case TypeCode.Double:
  3106. return true;
  3107. default:
  3108. return false;
  3109. }
  3110. }
  3111. public static Type GetNonNullableType(Type type) {
  3112. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  3113. type.GetGenericArguments()[0] :
  3114. type;
  3115. }
  3116. }
  3117. interface I {
  3118. void M();
  3119. }
  3120. public class C : IEquatable<C>, I {
  3121. void I.M() {
  3122. }
  3123. public override bool Equals(object o) {
  3124. return o is C && Equals((C) o);
  3125. }
  3126. public bool Equals(C c) {
  3127. return c != null;
  3128. }
  3129. public override int GetHashCode() {
  3130. return 0;
  3131. }
  3132. }
  3133. public class D : C, IEquatable<D> {
  3134. public int Val;
  3135. public D() {
  3136. }
  3137. public D(int val) {
  3138. Val = val;
  3139. }
  3140. public override bool Equals(object o) {
  3141. return o is D && Equals((D) o);
  3142. }
  3143. public bool Equals(D d) {
  3144. return d != null && d.Val == Val;
  3145. }
  3146. public override int GetHashCode() {
  3147. return Val;
  3148. }
  3149. }
  3150. public enum E {
  3151. A=1, B=2
  3152. }
  3153. public enum El : long {
  3154. A, B, C
  3155. }
  3156. public struct S : IEquatable<S> {
  3157. public override bool Equals(object o) {
  3158. return (o is S) && Equals((S) o);
  3159. }
  3160. public bool Equals(S other) {
  3161. return true;
  3162. }
  3163. public override int GetHashCode() {
  3164. return 0;
  3165. }
  3166. }
  3167. public struct Sp : IEquatable<Sp> {
  3168. public Sp(int i, double d) {
  3169. I = i;
  3170. D = d;
  3171. }
  3172. public int I;
  3173. public double D;
  3174. public override bool Equals(object o) {
  3175. return (o is Sp) && Equals((Sp) o);
  3176. }
  3177. public bool Equals(Sp other) {
  3178. return other.I == I && other.D == D;
  3179. }
  3180. public override int GetHashCode() {
  3181. return I.GetHashCode() ^ D.GetHashCode();
  3182. }
  3183. }
  3184. public struct Ss : IEquatable<Ss> {
  3185. public Ss(S s) {
  3186. Val = s;
  3187. }
  3188. public S Val;
  3189. public override bool Equals(object o) {
  3190. return (o is Ss) && Equals((Ss) o);
  3191. }
  3192. public bool Equals(Ss other) {
  3193. return other.Val.Equals(Val);
  3194. }
  3195. public override int GetHashCode() {
  3196. return Val.GetHashCode();
  3197. }
  3198. }
  3199. public struct Sc : IEquatable<Sc> {
  3200. public Sc(string s) {
  3201. S = s;
  3202. }
  3203. public string S;
  3204. public override bool Equals(object o) {
  3205. return (o is Sc) && Equals((Sc) o);
  3206. }
  3207. public bool Equals(Sc other) {
  3208. return other.S == S;
  3209. }
  3210. public override int GetHashCode() {
  3211. return S.GetHashCode();
  3212. }
  3213. }
  3214. public struct Scs : IEquatable<Scs> {
  3215. public Scs(string s, S val) {
  3216. S = s;
  3217. Val = val;
  3218. }
  3219. public string S;
  3220. public S Val;
  3221. public override bool Equals(object o) {
  3222. return (o is Scs) && Equals((Scs) o);
  3223. }
  3224. public bool Equals(Scs other) {
  3225. return other.S == S && other.Val.Equals(Val);
  3226. }
  3227. public override int GetHashCode() {
  3228. return S.GetHashCode() ^ Val.GetHashCode();
  3229. }
  3230. }
  3231. }
  3232. //-------- Scenario 3188
  3233. namespace Scenario3188{
  3234. public class Test
  3235. {
  3236. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Eq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  3237. public static Expression Eq_ArrayIndex__() {
  3238. if(Main() != 0 ) {
  3239. throw new Exception();
  3240. } else {
  3241. return Expression.Constant(0);
  3242. }
  3243. }
  3244. public static int Main()
  3245. {
  3246. Ext.StartCapture();
  3247. bool success = false;
  3248. try
  3249. {
  3250. success = check_Eq_ArrayIndex();
  3251. }
  3252. finally
  3253. {
  3254. Ext.StopCapture();
  3255. }
  3256. return success ? 0 : 1;
  3257. }
  3258. static bool check_Eq_ArrayIndex() {
  3259. return checkEx_Eq_ArrayIndex(null, -1) &
  3260. checkEx_Eq_ArrayIndex(null, 0) &
  3261. checkEx_Eq_ArrayIndex(null, 1) &
  3262. check_Eq_ArrayIndex(genArrEq_ArrayIndex(0)) &
  3263. check_Eq_ArrayIndex(genArrEq_ArrayIndex(1)) &
  3264. check_Eq_ArrayIndex(genArrEq_ArrayIndex(5));
  3265. }
  3266. static E?[] genArrEq_ArrayIndex(int size) {
  3267. E?[] vals = new E?[] { (E) 0, E.A, E.B, (E) int.MaxValue, (E) int.MinValue };
  3268. E?[] result = new E?[size];
  3269. for (int i = 0; i < size; i++) {
  3270. result[i] = vals[i % vals.Length];
  3271. }
  3272. return result;
  3273. }
  3274. static bool check_Eq_ArrayIndex(E?[] val) {
  3275. bool success = checkEx_Eq_ArrayIndex(val, -1);
  3276. for (int i = 0; i < val.Length; i++) {
  3277. success &= check_Eq_ArrayIndex(val, 0);
  3278. }
  3279. success &= checkEx_Eq_ArrayIndex(val, val.Length);
  3280. return success;
  3281. }
  3282. static bool checkEx_Eq_ArrayIndex(E?[] val, int index) {
  3283. try {
  3284. check_Eq_ArrayIndex(val, index);
  3285. Console.WriteLine("Eq_ArrayIndex[" + index + "] failed");
  3286. return false;
  3287. }
  3288. catch {
  3289. return true;
  3290. }
  3291. }
  3292. static bool check_Eq_ArrayIndex(E?[] val, int index) {
  3293. Expression<Func<E?>> e =
  3294. Expression.Lambda<Func<E?>>(
  3295. Expression.ArrayIndex(Expression.Constant(val, typeof(E?[])),
  3296. Expression.Constant(index, typeof(int))),
  3297. new System.Collections.Generic.List<ParameterExpression>());
  3298. Func<E?> f = e.Compile();
  3299. return object.Equals(f(), val[index]);
  3300. }
  3301. }
  3302. public static class Ext {
  3303. public static void StartCapture() {
  3304. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3305. // m.Invoke(null, new object[] { "test.dll" });
  3306. }
  3307. public static void StopCapture() {
  3308. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3309. // m.Invoke(null, new object[0]);
  3310. }
  3311. public static bool IsIntegralOrEnum(Type type) {
  3312. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3313. case TypeCode.Byte:
  3314. case TypeCode.SByte:
  3315. case TypeCode.Int16:
  3316. case TypeCode.Int32:
  3317. case TypeCode.Int64:
  3318. case TypeCode.UInt16:
  3319. case TypeCode.UInt32:
  3320. case TypeCode.UInt64:
  3321. return true;
  3322. default:
  3323. return false;
  3324. }
  3325. }
  3326. public static bool IsFloating(Type type) {
  3327. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3328. case TypeCode.Single:
  3329. case TypeCode.Double:
  3330. return true;
  3331. default:
  3332. return false;
  3333. }
  3334. }
  3335. public static Type GetNonNullableType(Type type) {
  3336. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  3337. type.GetGenericArguments()[0] :
  3338. type;
  3339. }
  3340. }
  3341. interface I {
  3342. void M();
  3343. }
  3344. public class C : IEquatable<C>, I {
  3345. void I.M() {
  3346. }
  3347. public override bool Equals(object o) {
  3348. return o is C && Equals((C) o);
  3349. }
  3350. public bool Equals(C c) {
  3351. return c != null;
  3352. }
  3353. public override int GetHashCode() {
  3354. return 0;
  3355. }
  3356. }
  3357. public class D : C, IEquatable<D> {
  3358. public int Val;
  3359. public D() {
  3360. }
  3361. public D(int val) {
  3362. Val = val;
  3363. }
  3364. public override bool Equals(object o) {
  3365. return o is D && Equals((D) o);
  3366. }
  3367. public bool Equals(D d) {
  3368. return d != null && d.Val == Val;
  3369. }
  3370. public override int GetHashCode() {
  3371. return Val;
  3372. }
  3373. }
  3374. public enum E {
  3375. A=1, B=2
  3376. }
  3377. public enum El : long {
  3378. A, B, C
  3379. }
  3380. public struct S : IEquatable<S> {
  3381. public override bool Equals(object o) {
  3382. return (o is S) && Equals((S) o);
  3383. }
  3384. public bool Equals(S other) {
  3385. return true;
  3386. }
  3387. public override int GetHashCode() {
  3388. return 0;
  3389. }
  3390. }
  3391. public struct Sp : IEquatable<Sp> {
  3392. public Sp(int i, double d) {
  3393. I = i;
  3394. D = d;
  3395. }
  3396. public int I;
  3397. public double D;
  3398. public override bool Equals(object o) {
  3399. return (o is Sp) && Equals((Sp) o);
  3400. }
  3401. public bool Equals(Sp other) {
  3402. return other.I == I && other.D == D;
  3403. }
  3404. public override int GetHashCode() {
  3405. return I.GetHashCode() ^ D.GetHashCode();
  3406. }
  3407. }
  3408. public struct Ss : IEquatable<Ss> {
  3409. public Ss(S s) {
  3410. Val = s;
  3411. }
  3412. public S Val;
  3413. public override bool Equals(object o) {
  3414. return (o is Ss) && Equals((Ss) o);
  3415. }
  3416. public bool Equals(Ss other) {
  3417. return other.Val.Equals(Val);
  3418. }
  3419. public override int GetHashCode() {
  3420. return Val.GetHashCode();
  3421. }
  3422. }
  3423. public struct Sc : IEquatable<Sc> {
  3424. public Sc(string s) {
  3425. S = s;
  3426. }
  3427. public string S;
  3428. public override bool Equals(object o) {
  3429. return (o is Sc) && Equals((Sc) o);
  3430. }
  3431. public bool Equals(Sc other) {
  3432. return other.S == S;
  3433. }
  3434. public override int GetHashCode() {
  3435. return S.GetHashCode();
  3436. }
  3437. }
  3438. public struct Scs : IEquatable<Scs> {
  3439. public Scs(string s, S val) {
  3440. S = s;
  3441. Val = val;
  3442. }
  3443. public string S;
  3444. public S Val;
  3445. public override bool Equals(object o) {
  3446. return (o is Scs) && Equals((Scs) o);
  3447. }
  3448. public bool Equals(Scs other) {
  3449. return other.S == S && other.Val.Equals(Val);
  3450. }
  3451. public override int GetHashCode() {
  3452. return S.GetHashCode() ^ Val.GetHashCode();
  3453. }
  3454. }
  3455. }
  3456. //-------- Scenario 3189
  3457. namespace Scenario3189{
  3458. public class Test
  3459. {
  3460. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Elq_ArrayIndex__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  3461. public static Expression Elq_ArrayIndex__() {
  3462. if(Main() != 0 ) {
  3463. throw new Exception();
  3464. } else {
  3465. return Expression.Constant(0);
  3466. }
  3467. }
  3468. public static int Main()
  3469. {
  3470. Ext.StartCapture();
  3471. bool success = false;
  3472. try
  3473. {
  3474. success = check_Elq_ArrayIndex();
  3475. }
  3476. finally
  3477. {
  3478. Ext.StopCapture();
  3479. }
  3480. return success ? 0 : 1;
  3481. }
  3482. static bool check_Elq_ArrayIndex() {
  3483. return checkEx_Elq_ArrayIndex(null, -1) &
  3484. checkEx_Elq_ArrayIndex(null, 0) &
  3485. checkEx_Elq_ArrayIndex(null, 1) &
  3486. check_Elq_ArrayIndex(genArrElq_ArrayIndex(0)) &
  3487. check_Elq_ArrayIndex(genArrElq_ArrayIndex(1)) &
  3488. check_Elq_ArrayIndex(genArrElq_ArrayIndex(5));
  3489. }
  3490. static El?[] genArrElq_ArrayIndex(int size) {
  3491. El?[] vals = new El?[] { (El) 0, El.A, El.B, (El) long.MaxValue, (El) long.MinValue };
  3492. El?[] result = new El?[size];
  3493. for (int i = 0; i < size; i++) {
  3494. result[i] = vals[i % vals.Length];
  3495. }
  3496. return result;
  3497. }
  3498. static bool check_Elq_ArrayIndex(El?[] val) {
  3499. bool success = checkEx_Elq_ArrayIndex(val, -1);
  3500. for (int i = 0; i < val.Length; i++) {
  3501. success &= check_Elq_ArrayIndex(val, 0);
  3502. }
  3503. success &= checkEx_Elq_ArrayIndex(val, val.Length);
  3504. return success;
  3505. }
  3506. static bool checkEx_Elq_ArrayIndex(El?[] val, int index) {
  3507. try {
  3508. check_Elq_ArrayIndex(val, index);
  3509. Console.WriteLine("Elq_ArrayIndex[" + index + "] failed");
  3510. return false;
  3511. }
  3512. catch {
  3513. return true;
  3514. }
  3515. }
  3516. static bool check_Elq_ArrayIndex(El?[] val, int index) {
  3517. Expression<Func<El?>> e =
  3518. Expression.Lambda<Func<El?>>(
  3519. Expression.ArrayIndex(Expression.Constant(val, typeof(El?[])),
  3520. Expression.Constant(index, typeof(int))),
  3521. new System.Collections.Generic.List<ParameterExpression>());
  3522. Func<El?> f = e.Compile();
  3523. return object.Equals(f(), val[index]);
  3524. }
  3525. }
  3526. public static class Ext {
  3527. public static void StartCapture() {
  3528. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3529. // m.Invoke(null, new object[] { "test.dll" });
  3530. }
  3531. public static void StopCapture() {
  3532. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  3533. // m.Invoke(null, new object[0]);
  3534. }
  3535. public static bool IsIntegralOrEnum(Type type) {
  3536. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3537. case TypeCode.Byte:
  3538. case TypeCode.SByte:
  3539. case TypeCode.Int16:
  3540. case TypeCode.Int32:
  3541. case TypeCode.Int64:
  3542. case TypeCode.UInt16:
  3543. case TypeCode.UInt32:
  3544. case TypeCode.UInt64:
  3545. return true;
  3546. default:
  3547. return false;
  3548. }
  3549. }
  3550. public static bool IsFloating(Type type) {
  3551. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  3552. case TypeCode.Single:
  3553. case TypeCode.Double:
  3554. return true;
  3555. default:
  3556. return false;
  3557. }
  3558. }
  3559. public static Type GetNonNullableType(Type type) {
  3560. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  3561. type.GetGenericArguments()[0] :
  3562. type;
  3563. }
  3564. }
  3565. interface I {
  3566. void M();
  3567. }
  3568. public class C : IEquatable<C>, I {
  3569. void I.M() {
  3570. }
  3571. public override bool Equals(object o) {
  3572. return o is C && Equals((C) o);
  3573. }
  3574. public bool Equals(C c) {
  3575. return c != null;
  3576. }
  3577. public override int GetHashCode() {
  3578. return 0;
  3579. }
  3580. }
  3581. public class D : C, IEquatable<D> {
  3582. public int Val;
  3583. public D() {
  3584. }
  3585. public D(int val) {
  3586. Val = val;
  3587. }
  3588. public override bool Equals(object o) {
  3589. return o is D && Equals((D) o);
  3590. }
  3591. public bool Equals(D d) {
  3592. return d != null && d.Val == Val;
  3593. }
  3594. public override int GetHashCode() {
  3595. return Val;
  3596. }
  3597. }
  3598. public enum E {
  3599. A=1, B=2
  3600. }
  3601. public enum El : long {
  3602. A, B, C
  3603. }
  3604. public struct S : IEquatable<S> {
  3605. public override bool Equals(object o) {
  3606. return (o is S) && Equals((S) o);
  3607. }
  3608. public bool Equals(S other) {
  3609. return true;
  3610. }
  3611. public override int GetHashCode() {
  3612. return 0;
  3613. }
  3614. }
  3615. public struct Sp : IEquatable<Sp> {
  3616. public Sp(int i, double d) {
  3617. I = i;
  3618. D = d;
  3619. }
  3620. public int I;
  3621. public double D;
  3622. public override bool Equals(object o) {
  3623. return (o is Sp) && Equals((Sp) o);
  3624. }
  3625. public bool Equals(Sp other) {
  3626. return other.I == I && other.D == D;
  3627. }
  3628. public override int GetHashCode() {
  3629. return I.GetHashCode() ^ D.GetHashCode();
  3630. }
  3631. }
  3632. public struct Ss : IEquatable<Ss> {
  3633. public Ss(S s) {
  3634. Val = s;
  3635. }
  3636. public S Val;
  3637. public override bool Equals(object o) {
  3638. return (o is Ss) && Equals((Ss) o);
  3639. }
  3640. public bool Equals(Ss other) {
  3641. return other.Val.Equals(Val);
  3642. }
  3643. public override int GetHashCode() {
  3644. return Val.GetHashCode();
  3645. }
  3646. }
  3647. public struct Sc : IEquatable<Sc> {
  3648. public Sc(string s) {
  3649. S = s;
  3650. }
  3651. public string S;
  3652. public override bool Equals(object o) {
  3653. return (o is Sc) && Equals((Sc) o);
  3654. }
  3655. public bool Equals(Sc other) {
  3656. return other.S == S;
  3657. }
  3658. public override int GetHashCode() {
  3659. return S.GetHashCode();
  3660. }
  3661. }
  3662. public struct Scs : IEquatable<Scs> {
  3663. public Scs(string s, S val) {
  3664. S = s;
  3665. Val = val;
  3666. }
  3667. public string S;
  3668. public S Val;
  3669. public override bool Equals(object o) {
  3670. return (o is Scs) && Equals((Scs) o);
  3671. }
  3672. public bool Equals(Scs other) {
  3673. return other.S == S && other.Val.Equals(Val);
  3674. }
  3675. public override int GetHashCode() {
  3676. return S.GetHashCode() ^ Val.GetHashCode();
  3677. }
  3678. }
  3679. }
  3680. }