diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs index 2e1442936..17c7ae6e1 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/LocalFunctions.cs @@ -27,12 +27,14 @@ namespace LocalFunctions { public int MixedLocalFunction() where T2 : ICloneable, IConvertible { + T2 t2 = default(T2); object z = this; for (int j = 0; j < 10; j++) { int i = 0; i += NonStaticMethod6(); int NonStaticMethod6() { + t2 = default(T2); int l = 0; return NonStaticMethod6_1() + NonStaticMethod6_1() + z.GetHashCode(); int NonStaticMethod6_1() @@ -48,13 +50,15 @@ namespace LocalFunctions } int StaticMethod1() where T3 : struct { - return typeof(T1).Name.Length + typeof(T2).Name.Length + typeof(T3).Name.Length + StaticMethod1() + StaticMethod1_1() + StaticMethod2(); + return typeof(T1).Name.Length + typeof(T2).Name.Length + typeof(T3).Name.Length + StaticMethod1() + StaticMethod1_1() + StaticMethod2_RepeatT2(); } 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 +#pragma warning disable CS8387 + int StaticMethod2_RepeatT2() where T2 : IConvertible where T3 : struct where T4 : Enum +#pragma warning restore CS8387 { return typeof(T2).Name.Length; } @@ -75,12 +79,14 @@ namespace LocalFunctions public int MixedLocalFunction2Delegate() where T2 : ICloneable, IConvertible { + T2 t2 = default(T2); object z = this; for (int j = 0; j < 10; j++) { int i = 0; i += StaticInvokeAsFunc(NonStaticMethod6); int NonStaticMethod6() { + t2 = default(T2); int l = 0; return StaticInvokeAsFunc(NonStaticMethod6_1) + StaticInvokeAsFunc(NonStaticMethod6_1) + z.GetHashCode(); int NonStaticMethod6_1() @@ -104,13 +110,15 @@ namespace LocalFunctions } 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); + return typeof(T1).Name.Length + typeof(T2).Name.Length + typeof(T3).Name.Length + StaticInvokeAsFunc(StaticMethod1) + StaticInvokeAsFunc(StaticMethod1_1) + StaticInvokeAsFunc(StaticMethod2_RepeatT2); } 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 +#pragma warning disable CS8387 + int StaticMethod2_RepeatT2() where T2 : IConvertible where T3 : struct where T4 : Enum +#pragma warning restore CS8387 { return typeof(T2).Name.Length; } @@ -128,6 +136,52 @@ namespace LocalFunctions } } } + + public static void Test_CaptureT() + { + T2 t2 = default(T2); + Method1(); + void Method1() + { + t2 = default(T2); + T2 t2x = t2; + T3 t3 = default(T3); + Method1_1(); + void Method1_1() + { + t2 = default(T2); + t2x = t2; + t3 = default(T3); + } + } + } + + public void TestGenericArgs() where T2 : List + { + ZZ(null); + ZZ2(null); + void Nop(T data) + { + } + void ZZ(T3 t3) where T3 : T2 + { + Nop>(t3); + ZZ1(t3); + ZZ3(); + void ZZ3() + { + Nop>(t3); + } + } + void ZZ1(T3 t3) + { + Nop>((List)(object)t3); + } + void ZZ2(T3 t3) + { + Nop>((List)(object)t3); + } + } } private int field; @@ -439,5 +493,53 @@ namespace LocalFunctions // } // } //} + + public void NestedCapture1() + { + Method1(null); + + Action Method1(Action action) + { + return Method1_1; + + void Method1_1(object containerBuilder) => + Method1_2(containerBuilder); + + void Method1_2(object containerBuilder) => + action(containerBuilder); + } + } + + public int NestedCapture2() + { + return Method(); + int Method() + { + int t0 = 0; + return ZZZ_0(); + int ZZZ_0() + { + t0 = 0; + var t1 = t0; + Func zzz2 = () => { + t0 = 0; + t1 = 0; + return ZZZ_1(); + }; + return zzz2(); + } + int ZZZ_1() + { + t0 = 0; + var t1 = t0; + Func zzz = () => { + t0 = 0; + t1 = 0; + return 0; + }; + return zzz(); + } + } + } } }