Skip to content

Commit 4203a68

Browse files
Extend test cases
1 parent 49368ca commit 4203a68

12 files changed

+481
-118
lines changed

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@
152152
<Compile Include="TestCases\Pretty\Issue3442.cs" />
153153
<Compile Include="TestCases\Pretty\Issue3483.cs" />
154154
<Compile Include="TestCases\Pretty\PointerArithmetic.cs" />
155-
<Compile Include="TestCases\Ugly\NoGenericTypeInstantiation.cs" />
156-
<None Include="TestCases\Ugly\NoGenericTypeInstantiation.Expected.cs" />
155+
<Compile Include="TestCases\Ugly\NoNewOfT.cs" />
156+
<None Include="TestCases\Ugly\NoNewOfT.Expected.cs" />
157157
<Compile Include="TestCases\Pretty\ParamsCollections.cs" />
158158
<None Include="TestCases\VBPretty\VBAutomaticEvents.vb" />
159159
<Compile Include="TestCases\VBPretty\VBAutomaticEvents.cs" />

ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoGenericTypeInstantiation.Expected.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoGenericTypeInstantiation.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
5+
{
6+
internal class NoNewOfT<TOnType> where TOnType : new()
7+
{
8+
public static TOnType CreateTOnType()
9+
{
10+
#if !ROSLYN
11+
#if OPT
12+
if (default(TOnType) != null)
13+
{
14+
return default(TOnType);
15+
}
16+
return Activator.CreateInstance<TOnType>();
17+
#else
18+
return (default(TOnType) == null) ? Activator.CreateInstance<TOnType>() : default(TOnType);
19+
#endif
20+
#else
21+
return Activator.CreateInstance<TOnType>();
22+
#endif
23+
}
24+
25+
public static T CreateUnconstrainedT<T>() where T : new()
26+
{
27+
#if !ROSLYN
28+
#if OPT
29+
if (default(T) != null)
30+
{
31+
return default(T);
32+
}
33+
return Activator.CreateInstance<T>();
34+
#else
35+
return (default(T) == null) ? Activator.CreateInstance<T>() : default(T);
36+
#endif
37+
#else
38+
return Activator.CreateInstance<T>();
39+
#endif
40+
}
41+
42+
public static T CreateClassT<T>() where T : class, new()
43+
{
44+
return Activator.CreateInstance<T>();
45+
}
46+
47+
public static T CollectionInitializer<T>() where T : IList<int>, new()
48+
{
49+
#if ROSLYN
50+
T result = Activator.CreateInstance<T>();
51+
result.Add(1);
52+
result.Add(2);
53+
result.Add(3);
54+
result.Add(4);
55+
result.Add(5);
56+
return result;
57+
#else
58+
T val = ((default(T) == null) ? Activator.CreateInstance<T>() : default(T));
59+
val.Add(1);
60+
val.Add(2);
61+
val.Add(3);
62+
val.Add(4);
63+
val.Add(5);
64+
return val;
65+
#endif
66+
}
67+
}
68+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
3+
namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
4+
{
5+
internal class NoNewOfT<TOnType> where TOnType : new()
6+
{
7+
public static TOnType CreateTOnType()
8+
{
9+
return new TOnType();
10+
}
11+
12+
public static T CreateUnconstrainedT<T>() where T : new()
13+
{
14+
return new T();
15+
}
16+
17+
public static T CreateClassT<T>() where T : class, new()
18+
{
19+
return new T();
20+
}
21+
22+
public static T CollectionInitializer<T>() where T : IList<int>, new()
23+
{
24+
return new T() { 1, 2, 3, 4, 5 };
25+
}
26+
}
27+
}

ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoGenericTypeInstantiation.il renamed to ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.il

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
1010
.ver 4:0:0:0
1111
}
12-
.assembly tmppi3wbt
12+
.assembly tmpvpdwr1
1313
{
1414
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
1515
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
@@ -19,8 +19,8 @@
1919
.hash algorithm 0x00008004
2020
.ver 0:0:0:0
2121
}
22-
.module tmppi3wbt.tmp
23-
// MVID: {4130db71-37be-40af-9724-d988f7189866}
22+
.module tmpvpdwr1.tmp
23+
// MVID: {8447adbb-757d-4626-b7b7-846d745d90d0}
2424
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
2525
.imagebase 0x10000000
2626
.file alignment 0x00000200
@@ -31,7 +31,7 @@
3131

3232
// =============== CLASS MEMBERS DECLARATION ===================
3333

34-
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoGenericTypeInstantiation`1<.ctor TOnType>
34+
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1<.ctor TOnType>
3535
extends [mscorlib]System.Object
3636
{
3737
.method public hidebysig static !TOnType
@@ -60,24 +60,23 @@
6060

6161
IL_0025: ldloc.0
6262
IL_0026: ret
63-
} // end of method NoGenericTypeInstantiation`1::CreateTOnType
63+
} // end of method NoNewOfT`1::CreateTOnType
6464

65-
.method public hidebysig static !!TOnMethod
66-
CreateTOnMethod<.ctor TOnMethod>() cil managed
65+
.method public hidebysig static !!T CreateUnconstrainedT<.ctor T>() cil managed
6766
{
6867
// Code size 39 (0x27)
6968
.maxstack 1
70-
.locals init (!!TOnMethod V_0,
71-
!!TOnMethod V_1)
69+
.locals init (!!T V_0,
70+
!!T V_1)
7271
IL_0000: nop
7372
IL_0001: ldloca.s V_1
74-
IL_0003: initobj !!TOnMethod
73+
IL_0003: initobj !!T
7574
IL_0009: ldloc.1
76-
IL_000a: box !!TOnMethod
75+
IL_000a: box !!T
7776
IL_000f: brfalse.s IL_001c
7877

7978
IL_0011: ldloca.s V_1
80-
IL_0013: initobj !!TOnMethod
79+
IL_0013: initobj !!T
8180
IL_0019: ldloc.1
8281
IL_001a: br.s IL_0021
8382

@@ -88,7 +87,76 @@
8887

8988
IL_0025: ldloc.0
9089
IL_0026: ret
91-
} // end of method NoGenericTypeInstantiation`1::CreateTOnMethod
90+
} // end of method NoNewOfT`1::CreateUnconstrainedT
91+
92+
.method public hidebysig static !!T CreateClassT<class .ctor T>() cil managed
93+
{
94+
// Code size 11 (0xb)
95+
.maxstack 1
96+
.locals init (!!T V_0)
97+
IL_0000: nop
98+
IL_0001: call !!0 [mscorlib]System.Activator::CreateInstance<!!0>()
99+
IL_0006: stloc.0
100+
IL_0007: br.s IL_0009
101+
102+
IL_0009: ldloc.0
103+
IL_000a: ret
104+
} // end of method NoNewOfT`1::CreateClassT
105+
106+
.method public hidebysig static !!T CollectionInitializer<.ctor (class [mscorlib]System.Collections.Generic.IList`1<int32>) T>() cil managed
107+
{
108+
// Code size 106 (0x6a)
109+
.maxstack 2
110+
.locals init (!!T V_0,
111+
!!T V_1,
112+
!!T V_2)
113+
IL_0000: nop
114+
IL_0001: ldloca.s V_2
115+
IL_0003: initobj !!T
116+
IL_0009: ldloc.2
117+
IL_000a: box !!T
118+
IL_000f: brfalse.s IL_001c
119+
120+
IL_0011: ldloca.s V_2
121+
IL_0013: initobj !!T
122+
IL_0019: ldloc.2
123+
IL_001a: br.s IL_0021
124+
125+
IL_001c: call !!0 [mscorlib]System.Activator::CreateInstance<!!0>()
126+
IL_0021: nop
127+
IL_0022: stloc.0
128+
IL_0023: ldloc.0
129+
IL_0024: box !!T
130+
IL_0029: ldc.i4.1
131+
IL_002a: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<int32>::Add(!0)
132+
IL_002f: nop
133+
IL_0030: ldloc.0
134+
IL_0031: box !!T
135+
IL_0036: ldc.i4.2
136+
IL_0037: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<int32>::Add(!0)
137+
IL_003c: nop
138+
IL_003d: ldloc.0
139+
IL_003e: box !!T
140+
IL_0043: ldc.i4.3
141+
IL_0044: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<int32>::Add(!0)
142+
IL_0049: nop
143+
IL_004a: ldloc.0
144+
IL_004b: box !!T
145+
IL_0050: ldc.i4.4
146+
IL_0051: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<int32>::Add(!0)
147+
IL_0056: nop
148+
IL_0057: ldloc.0
149+
IL_0058: box !!T
150+
IL_005d: ldc.i4.5
151+
IL_005e: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<int32>::Add(!0)
152+
IL_0063: nop
153+
IL_0064: ldloc.0
154+
IL_0065: stloc.1
155+
IL_0066: br.s IL_0068
156+
157+
IL_0068: ldloc.1
158+
IL_0069: ret
159+
} // end of method NoNewOfT`1::CollectionInitializer
92160

93161
.method public hidebysig specialname rtspecialname
94162
instance void .ctor() cil managed
@@ -98,9 +166,9 @@
98166
IL_0000: ldarg.0
99167
IL_0001: call instance void [mscorlib]System.Object::.ctor()
100168
IL_0006: ret
101-
} // end of method NoGenericTypeInstantiation`1::.ctor
169+
} // end of method NoNewOfT`1::.ctor
102170

103-
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoGenericTypeInstantiation`1
171+
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1
104172

105173

106174
// =============================================================

0 commit comments

Comments
 (0)