From d88c73f59df9360636dc1b37ce98ee9713e135a0 Mon Sep 17 00:00:00 2001 From: SilverFox Date: Thu, 14 Nov 2019 22:33:30 +0800 Subject: [PATCH] Add test for generic local function --- .../TestCases/Pretty/LocalFunctions.cs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs index 91c58bacd..2e1442936 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs @@ -23,6 +23,113 @@ namespace LocalFunctions { internal class LocalFunctions { + public class Generic where T1 : struct, ICloneable, IConvertible + { + public int MixedLocalFunction() where T2 : ICloneable, IConvertible + { + object z = this; + for (int j = 0; j < 10; j++) { + int i = 0; + i += NonStaticMethod6(); + int NonStaticMethod6() + { + int l = 0; + return NonStaticMethod6_1() + NonStaticMethod6_1() + z.GetHashCode(); + int NonStaticMethod6_1() + { + return i + l + NonStaticMethod6() + StaticMethod1(); + } + } + } + return MixedLocalFunction() + MixedLocalFunction() + StaticMethod1() + StaticMethod1() + NonStaticMethod3() + StaticMethod4(null) + StaticMethod5(); + int NonStaticMethod3() + { + return GetHashCode(); + } + int StaticMethod1() where T3 : struct + { + return typeof(T1).Name.Length + typeof(T2).Name.Length + typeof(T3).Name.Length + StaticMethod1() + StaticMethod1_1() + StaticMethod2(); + } + int StaticMethod1_1() where T3 : struct where T4 : Enum + { + return typeof(T1).Name.Length + typeof(T2).Name.Length + typeof(T3).Name.Length + typeof(T4).Name.Length + StaticMethod1() + StaticMethod1_1(); + } + int StaticMethod2() where T2 : IConvertible where T3 : struct where T4 : Enum + { + return typeof(T2).Name.Length; + } + int StaticMethod4(T dd) + { + return 0; + } + int StaticMethod5() + { + int k = 0; + return k + NonStaticMethod5_1(); + int NonStaticMethod5_1() + { + return k; + } + } + } + + public int MixedLocalFunction2Delegate() where T2 : ICloneable, IConvertible + { + object z = this; + for (int j = 0; j < 10; j++) { + int i = 0; + i += StaticInvokeAsFunc(NonStaticMethod6); + int NonStaticMethod6() + { + int l = 0; + return StaticInvokeAsFunc(NonStaticMethod6_1) + StaticInvokeAsFunc(NonStaticMethod6_1) + z.GetHashCode(); + int NonStaticMethod6_1() + { + return i + l + StaticInvokeAsFunc(NonStaticMethod6) + StaticInvokeAsFunc(StaticMethod1); + } + } + } + return StaticInvokeAsFunc(MixedLocalFunction2Delegate) + StaticInvokeAsFunc(MixedLocalFunction2Delegate) + StaticInvokeAsFunc(StaticMethod1) + StaticInvokeAsFunc(StaticMethod1) + StaticInvokeAsFunc(NonStaticMethod3) + StaticInvokeAsFunc(StaticMethod5) + new Func(StaticMethod4)(null) + StaticInvokeAsFunc2(StaticMethod4) + new Func, int>(StaticInvokeAsFunc2)(StaticMethod4); + int NonStaticMethod3() + { + return GetHashCode(); + } + int StaticInvokeAsFunc(Func func) + { + return func(); + } + int StaticInvokeAsFunc2(Func func) + { + return func(default(T)); + } + int StaticMethod1() where T3 : struct + { + return typeof(T1).Name.Length + typeof(T2).Name.Length + typeof(T3).Name.Length + StaticInvokeAsFunc(StaticMethod1) + StaticInvokeAsFunc(StaticMethod1_1) + StaticInvokeAsFunc(StaticMethod2); + } + int StaticMethod1_1() where T3 : struct where T4 : Enum + { + return typeof(T1).Name.Length + typeof(T2).Name.Length + typeof(T3).Name.Length + typeof(T4).Name.Length + StaticInvokeAsFunc(StaticMethod1) + StaticInvokeAsFunc(StaticMethod1_1); + } + int StaticMethod2() where T2 : IConvertible where T3 : struct where T4 : Enum + { + return typeof(T2).Name.Length; + } + int StaticMethod4(T dd) + { + return 0; + } + int StaticMethod5() + { + int k = 0; + return k + StaticInvokeAsFunc(NonStaticMethod5_1); + int NonStaticMethod5_1() + { + return k; + } + } + } + } + private int field; private Lazy nonCapturinglocalFunctionInLambda = new Lazy(delegate {