Browse Source

Fix #1250: Missing enum to int cast in object initializer

pull/1274/merge
Siegfried Pammer 7 years ago
parent
commit
a9c1b9d515
  1. 51
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  2. 121
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il
  3. 105
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il
  4. 157
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il
  5. 183
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il
  6. 24
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  7. 94
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  8. 9
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

51
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

@ -62,6 +62,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -62,6 +62,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
public int Z;
public S Y;
public List<S> L;
public S this[int index] {
get {
return default(S);
}
set {
}
}
public S this[object key] {
get {
return default(S);
}
set {
}
}
}
public struct S
@ -542,7 +558,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -542,7 +558,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
});
}
public void NestedListWithIndexInitializer()
private void NestedListWithIndexInitializer(MyEnum myEnum)
{
#if !OPT
List<List<int>> list = new List<List<int>> {
@ -553,6 +569,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -553,6 +569,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
1,
2,
3
},
[1] = {
(int)myEnum
}
};
}
@ -684,6 +703,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -684,6 +703,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
});
}
private void Issue1250_Test1(MyEnum value)
{
X(Y(), new C {
Z = (int)value
});
}
#if CS60
private void Issue1250_Test2(MyEnum value)
{
X(Y(), new C {
[(int)value] = new S((int)value)
});
}
private void Issue1250_Test3(int value)
{
X(Y(), new C {
[value] = new S(value)
});
}
private void Issue1250_Test4(int value)
{
X(Y(), new C {
[(object)value] = new S(value)
});
}
#endif
private void Issue1251_Test(List<Item> list, OtherItem otherItem)
{
list.Add(new Item {

121
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il

@ -125,9 +125,68 @@ @@ -125,9 +125,68 @@
.class auto ansi nested public beforefieldinit C
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item..
.field public int32 Z
.field public valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S Y
.field public class [mscorlib]System.Collections.Generic.List`1<valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S> L
.method public hidebysig specialname
instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
get_Item(int32 index) cil managed
{
// Code size 15 (0xf)
.maxstack 1
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_0,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_1)
IL_0000: nop
IL_0001: ldloca.s V_1
IL_0003: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
IL_0009: ldloc.1
IL_000a: stloc.0
IL_000b: br.s IL_000d
IL_000d: ldloc.0
IL_000e: ret
} // end of method C::get_Item
.method public hidebysig specialname
instance void set_Item(int32 index,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S 'value') cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method C::set_Item
.method public hidebysig specialname
instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
get_Item(object key) cil managed
{
// Code size 15 (0xf)
.maxstack 1
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_0,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_1)
IL_0000: nop
IL_0001: ldloca.s V_1
IL_0003: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
IL_0009: ldloc.1
IL_000a: stloc.0
IL_000b: br.s IL_000d
IL_000d: ldloc.0
IL_000e: ret
} // end of method C::get_Item
.method public hidebysig specialname
instance void set_Item(object key,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S 'value') cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method C::set_Item
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -138,6 +197,20 @@ @@ -138,6 +197,20 @@
IL_0006: ret
} // end of method C::.ctor
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
Item(int32)
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::get_Item(int32)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(int32,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
} // end of property C::Item
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
Item(object)
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::get_Item(object)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(object,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
} // end of property C::Item
} // end of class C
.class sequential ansi sealed nested public beforefieldinit S
@ -495,8 +568,8 @@ @@ -495,8 +568,8 @@
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum
a()
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_a()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum)
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_a()
} // end of property Data::a
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum
b()
@ -513,8 +586,8 @@ @@ -513,8 +586,8 @@
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data
MoreData()
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_MoreData()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data)
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_MoreData()
} // end of property Data::MoreData
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData
NestedStruct()
@ -525,9 +598,9 @@ @@ -525,9 +598,9 @@
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data
Item(int32)
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_Item(int32)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::set_Item(int32,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data)
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_Item(int32)
} // end of property Data::Item
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data
Item(int32,
@ -626,14 +699,14 @@ @@ -626,14 +699,14 @@
.property instance int32 Property()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::set_Property(int32)
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::get_Property()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::set_Property(int32)
} // end of property StructData::Property
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data
MoreData()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data)
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::get_MoreData()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data)
} // end of property StructData::MoreData
} // end of class StructData
@ -870,14 +943,14 @@ @@ -870,14 +943,14 @@
.property instance valuetype [mscorlib]System.Decimal
Value()
{
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value(valuetype [mscorlib]System.Decimal)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value()
} // end of property Item::Value
.property instance valuetype [mscorlib]System.Decimal
Value2()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value2(valuetype [mscorlib]System.Decimal)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value2(valuetype [mscorlib]System.Decimal)
} // end of property Item::Value2
.property instance string Value3()
{
@ -886,18 +959,18 @@ @@ -886,18 +959,18 @@
} // end of property Item::Value3
.property instance string Value4()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value4()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value4(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value4()
} // end of property Item::Value4
.property instance string Value5()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value5(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value5()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value5(string)
} // end of property Item::Value5
.property instance string Value6()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value6()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value6(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value6()
} // end of property Item::Value6
} // end of class Item
@ -1103,20 +1176,20 @@ @@ -1103,20 +1176,20 @@
.property instance valuetype [mscorlib]System.Decimal
Value()
{
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Value()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Value(valuetype [mscorlib]System.Decimal)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Value()
} // end of property OtherItem::Value
.property instance valuetype [mscorlib]System.Decimal
Value2()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Value2(valuetype [mscorlib]System.Decimal)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Value2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Value2(valuetype [mscorlib]System.Decimal)
} // end of property OtherItem::Value2
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable()
{
.get instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Nullable()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
.get instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Nullable()
} // end of property OtherItem::Nullable
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable2()
@ -1127,8 +1200,8 @@ @@ -1127,8 +1200,8 @@
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable3()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable3(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
.get instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Nullable3()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable3(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
} // end of property OtherItem::Nullable3
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable4()
@ -2290,6 +2363,26 @@ @@ -2290,6 +2363,26 @@
IL_0020: ret
} // end of method TestCases::Issue907_Test3
.method private hidebysig instance void
Issue1250_Test1(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum 'value') cil managed
{
// Code size 27 (0x1b)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C V_0)
IL_0000: nop
IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000b: stloc.0
IL_000c: ldloc.0
IL_000d: ldarg.1
IL_000e: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::Z
IL_0013: ldloc.0
IL_0014: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_0019: nop
IL_001a: ret
} // end of method TestCases::Issue1250_Test1
.method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed

105
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il

@ -119,9 +119,54 @@ @@ -119,9 +119,54 @@
.class auto ansi nested public beforefieldinit C
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item..
.field public int32 Z
.field public valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S Y
.field public class [mscorlib]System.Collections.Generic.List`1<valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S> L
.method public hidebysig specialname
instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
get_Item(int32 index) cil managed
{
// Code size 10 (0xa)
.maxstack 1
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_0)
IL_0000: ldloca.s V_0
IL_0002: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
IL_0008: ldloc.0
IL_0009: ret
} // end of method C::get_Item
.method public hidebysig specialname
instance void set_Item(int32 index,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S 'value') cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method C::set_Item
.method public hidebysig specialname
instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
get_Item(object key) cil managed
{
// Code size 10 (0xa)
.maxstack 1
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_0)
IL_0000: ldloca.s V_0
IL_0002: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
IL_0008: ldloc.0
IL_0009: ret
} // end of method C::get_Item
.method public hidebysig specialname
instance void set_Item(object key,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S 'value') cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method C::set_Item
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -132,6 +177,20 @@ @@ -132,6 +177,20 @@
IL_0006: ret
} // end of method C::.ctor
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
Item(int32)
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::get_Item(int32)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(int32,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
} // end of property C::Item
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
Item(object)
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::get_Item(object)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(object,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
} // end of property C::Item
} // end of class C
.class sequential ansi sealed nested public beforefieldinit S
@ -436,8 +495,8 @@ @@ -436,8 +495,8 @@
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum
a()
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_a()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::set_a(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum)
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_a()
} // end of property Data::a
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum
b()
@ -454,8 +513,8 @@ @@ -454,8 +513,8 @@
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data
MoreData()
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_MoreData()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data)
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_MoreData()
} // end of property Data::MoreData
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData
NestedStruct()
@ -466,9 +525,9 @@ @@ -466,9 +525,9 @@
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data
Item(int32)
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_Item(int32)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::set_Item(int32,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data)
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::get_Item(int32)
} // end of property Data::Item
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data
Item(int32,
@ -555,14 +614,14 @@ @@ -555,14 +614,14 @@
.property instance int32 Property()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::set_Property(int32)
.get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::get_Property()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::set_Property(int32)
} // end of property StructData::Property
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data
MoreData()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data)
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::get_MoreData()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/StructData::set_MoreData(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data)
} // end of property StructData::MoreData
} // end of class StructData
@ -764,14 +823,14 @@ @@ -764,14 +823,14 @@
.property instance valuetype [mscorlib]System.Decimal
Value()
{
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value(valuetype [mscorlib]System.Decimal)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value()
} // end of property Item::Value
.property instance valuetype [mscorlib]System.Decimal
Value2()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value2(valuetype [mscorlib]System.Decimal)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value2(valuetype [mscorlib]System.Decimal)
} // end of property Item::Value2
.property instance string Value3()
{
@ -780,18 +839,18 @@ @@ -780,18 +839,18 @@
} // end of property Item::Value3
.property instance string Value4()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value4()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value4(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value4()
} // end of property Item::Value4
.property instance string Value5()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value5(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value5()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value5(string)
} // end of property Item::Value5
.property instance string Value6()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value6()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value6(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value6()
} // end of property Item::Value6
} // end of class Item
@ -967,20 +1026,20 @@ @@ -967,20 +1026,20 @@
.property instance valuetype [mscorlib]System.Decimal
Value()
{
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Value()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Value(valuetype [mscorlib]System.Decimal)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Value()
} // end of property OtherItem::Value
.property instance valuetype [mscorlib]System.Decimal
Value2()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Value2(valuetype [mscorlib]System.Decimal)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Value2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Value2(valuetype [mscorlib]System.Decimal)
} // end of property OtherItem::Value2
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable()
{
.get instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Nullable()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
.get instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Nullable()
} // end of property OtherItem::Nullable
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable2()
@ -991,8 +1050,8 @@ @@ -991,8 +1050,8 @@
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable3()
{
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable3(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
.get instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Nullable3()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable3(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
} // end of property OtherItem::Nullable3
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable4()
@ -1963,6 +2022,24 @@ @@ -1963,6 +2022,24 @@
IL_001d: ret
} // end of method TestCases::Issue907_Test3
.method private hidebysig instance void
Issue1250_Test1(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum 'value') cil managed
{
// Code size 25 (0x19)
.maxstack 3
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C V_0)
IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000a: stloc.0
IL_000b: ldloc.0
IL_000c: ldarg.1
IL_000d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::Z
IL_0012: ldloc.0
IL_0013: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_0018: ret
} // end of method TestCases::Issue1250_Test1
.method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed

157
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il

@ -123,9 +123,54 @@ @@ -123,9 +123,54 @@
.class auto ansi nested public beforefieldinit C
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item..
.field public int32 Z
.field public valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S Y
.field public class [mscorlib]System.Collections.Generic.List`1<valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S> L
.method public hidebysig specialname
instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
get_Item(int32 index) cil managed
{
// Code size 10 (0xa)
.maxstack 1
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_0)
IL_0000: ldloca.s V_0
IL_0002: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
IL_0008: ldloc.0
IL_0009: ret
} // end of method C::get_Item
.method public hidebysig specialname
instance void set_Item(int32 index,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S 'value') cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method C::set_Item
.method public hidebysig specialname
instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
get_Item(object key) cil managed
{
// Code size 10 (0xa)
.maxstack 1
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_0)
IL_0000: ldloca.s V_0
IL_0002: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
IL_0008: ldloc.0
IL_0009: ret
} // end of method C::get_Item
.method public hidebysig specialname
instance void set_Item(object key,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S 'value') cil managed
{
// Code size 1 (0x1)
.maxstack 8
IL_0000: ret
} // end of method C::set_Item
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -136,6 +181,20 @@ @@ -136,6 +181,20 @@
IL_0006: ret
} // end of method C::.ctor
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
Item(int32)
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::get_Item(int32)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(int32,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
} // end of property C::Item
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
Item(object)
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::get_Item(object)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(object,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
} // end of property C::Item
} // end of class C
.class sequential ansi sealed nested public beforefieldinit S
@ -1697,10 +1756,10 @@ @@ -1697,10 +1756,10 @@
IL_0081: ret
} // end of method TestCases::MixedObjectAndDictInitializer
.method public hidebysig instance void
NestedListWithIndexInitializer() cil managed
.method private hidebysig instance void
NestedListWithIndexInitializer(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum myEnum) cil managed
{
// Code size 46 (0x2e)
// Code size 59 (0x3b)
.maxstack 8
IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Collections.Generic.List`1<int32>>::.ctor()
IL_0005: dup
@ -1718,8 +1777,13 @@ @@ -1718,8 +1777,13 @@
IL_0021: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Collections.Generic.List`1<int32>>::get_Item(int32)
IL_0026: ldc.i4.3
IL_0027: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<int32>::Add(!0)
IL_002c: pop
IL_002d: ret
IL_002c: dup
IL_002d: ldc.i4.1
IL_002e: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Collections.Generic.List`1<int32>>::get_Item(int32)
IL_0033: ldarg.1
IL_0034: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<int32>::Add(!0)
IL_0039: pop
IL_003a: ret
} // end of method TestCases::NestedListWithIndexInitializer
.method public hidebysig static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() cil managed
@ -1993,6 +2057,85 @@ @@ -1993,6 +2057,85 @@
IL_001b: ret
} // end of method TestCases::Issue907_Test3
.method private hidebysig instance void
Issue1250_Test1(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum 'value') cil managed
{
// Code size 23 (0x17)
.maxstack 8
IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000a: dup
IL_000b: ldarg.1
IL_000c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::Z
IL_0011: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_0016: ret
} // end of method TestCases::Issue1250_Test1
.method private hidebysig instance void
Issue1250_Test2(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum 'value') cil managed
{
// Code size 31 (0x1f)
.maxstack 5
.locals init (int32 V_0)
IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000a: ldarg.1
IL_000b: stloc.0
IL_000c: dup
IL_000d: ldloc.0
IL_000e: ldarg.1
IL_000f: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S::.ctor(int32)
IL_0014: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(int32,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
IL_0019: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_001e: ret
} // end of method TestCases::Issue1250_Test2
.method private hidebysig instance void
Issue1250_Test3(int32 'value') cil managed
{
// Code size 31 (0x1f)
.maxstack 5
.locals init (int32 V_0)
IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000a: ldarg.1
IL_000b: stloc.0
IL_000c: dup
IL_000d: ldloc.0
IL_000e: ldarg.1
IL_000f: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S::.ctor(int32)
IL_0014: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(int32,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
IL_0019: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_001e: ret
} // end of method TestCases::Issue1250_Test3
.method private hidebysig instance void
Issue1250_Test4(int32 'value') cil managed
{
// Code size 36 (0x24)
.maxstack 5
.locals init (object V_0)
IL_0000: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0005: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000a: ldarg.1
IL_000b: box [mscorlib]System.Int32
IL_0010: stloc.0
IL_0011: dup
IL_0012: ldloc.0
IL_0013: ldarg.1
IL_0014: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S::.ctor(int32)
IL_0019: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(object,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
IL_001e: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_0023: ret
} // end of method TestCases::Issue1250_Test4
.method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -2072,13 +2215,13 @@ @@ -2072,13 +2215,13 @@
.size 40
} // end of class '__StaticArrayInitTypeSize=40'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00004ED0
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00005108
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_00004ED0 = bytearray (
.data cil I_00005108 = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00
09 00 00 00 0A 00 00 00)

183
ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il

@ -130,9 +130,68 @@ @@ -130,9 +130,68 @@
.class auto ansi nested public beforefieldinit C
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( 01 00 04 49 74 65 6D 00 00 ) // ...Item..
.field public int32 Z
.field public valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S Y
.field public class [mscorlib]System.Collections.Generic.List`1<valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S> L
.method public hidebysig specialname
instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
get_Item(int32 index) cil managed
{
// Code size 15 (0xf)
.maxstack 1
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_0,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_1)
IL_0000: nop
IL_0001: ldloca.s V_0
IL_0003: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
IL_0009: ldloc.0
IL_000a: stloc.1
IL_000b: br.s IL_000d
IL_000d: ldloc.1
IL_000e: ret
} // end of method C::get_Item
.method public hidebysig specialname
instance void set_Item(int32 index,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S 'value') cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method C::set_Item
.method public hidebysig specialname
instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
get_Item(object key) cil managed
{
// Code size 15 (0xf)
.maxstack 1
.locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_0,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S V_1)
IL_0000: nop
IL_0001: ldloca.s V_0
IL_0003: initobj ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
IL_0009: ldloc.0
IL_000a: stloc.1
IL_000b: br.s IL_000d
IL_000d: ldloc.1
IL_000e: ret
} // end of method C::get_Item
.method public hidebysig specialname
instance void set_Item(object key,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S 'value') cil managed
{
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method C::set_Item
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -144,6 +203,20 @@ @@ -144,6 +203,20 @@
IL_0007: ret
} // end of method C::.ctor
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
Item(int32)
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::get_Item(int32)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(int32,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
} // end of property C::Item
.property instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S
Item(object)
{
.get instance valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::get_Item(object)
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(object,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
} // end of property C::Item
} // end of class C
.class sequential ansi sealed nested public beforefieldinit S
@ -1918,10 +1991,10 @@ @@ -1918,10 +1991,10 @@
IL_0088: ret
} // end of method TestCases::MixedObjectAndDictInitializer
.method public hidebysig instance void
NestedListWithIndexInitializer() cil managed
.method private hidebysig instance void
NestedListWithIndexInitializer(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum myEnum) cil managed
{
// Code size 50 (0x32)
// Code size 64 (0x40)
.maxstack 3
.locals init (class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Collections.Generic.List`1<int32>> V_0)
IL_0000: nop
@ -1944,8 +2017,14 @@ @@ -1944,8 +2017,14 @@
IL_0029: ldc.i4.3
IL_002a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<int32>::Add(!0)
IL_002f: nop
IL_0030: stloc.0
IL_0031: ret
IL_0030: dup
IL_0031: ldc.i4.1
IL_0032: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1<class [mscorlib]System.Collections.Generic.List`1<int32>>::get_Item(int32)
IL_0037: ldarg.1
IL_0038: callvirt instance void class [mscorlib]System.Collections.Generic.List`1<int32>::Add(!0)
IL_003d: nop
IL_003e: stloc.0
IL_003f: ret
} // end of method TestCases::NestedListWithIndexInitializer
.method public hidebysig static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() cil managed
@ -2263,6 +2342,96 @@ @@ -2263,6 +2342,96 @@
IL_001e: ret
} // end of method TestCases::Issue907_Test3
.method private hidebysig instance void
Issue1250_Test1(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum 'value') cil managed
{
// Code size 25 (0x19)
.maxstack 8
IL_0000: nop
IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000b: dup
IL_000c: ldarg.1
IL_000d: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::Z
IL_0012: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_0017: nop
IL_0018: ret
} // end of method TestCases::Issue1250_Test1
.method private hidebysig instance void
Issue1250_Test2(valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/MyEnum 'value') cil managed
{
// Code size 34 (0x22)
.maxstack 5
.locals init (int32 V_0)
IL_0000: nop
IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000b: ldarg.1
IL_000c: stloc.0
IL_000d: dup
IL_000e: ldloc.0
IL_000f: ldarg.1
IL_0010: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S::.ctor(int32)
IL_0015: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(int32,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
IL_001a: nop
IL_001b: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_0020: nop
IL_0021: ret
} // end of method TestCases::Issue1250_Test2
.method private hidebysig instance void
Issue1250_Test3(int32 'value') cil managed
{
// Code size 34 (0x22)
.maxstack 5
.locals init (int32 V_0)
IL_0000: nop
IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000b: ldarg.1
IL_000c: stloc.0
IL_000d: dup
IL_000e: ldloc.0
IL_000f: ldarg.1
IL_0010: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S::.ctor(int32)
IL_0015: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(int32,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
IL_001a: nop
IL_001b: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_0020: nop
IL_0021: ret
} // end of method TestCases::Issue1250_Test3
.method private hidebysig instance void
Issue1250_Test4(int32 'value') cil managed
{
// Code size 39 (0x27)
.maxstack 5
.locals init (object V_0)
IL_0000: nop
IL_0001: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0006: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::.ctor()
IL_000b: ldarg.1
IL_000c: box [mscorlib]System.Int32
IL_0011: stloc.0
IL_0012: dup
IL_0013: ldloc.0
IL_0014: ldarg.1
IL_0015: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S::.ctor(int32)
IL_001a: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/C::set_Item(object,
valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/S)
IL_001f: nop
IL_0020: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::X(object,
object)
IL_0025: nop
IL_0026: ret
} // end of method TestCases::Issue1250_Test4
.method private hidebysig instance void
Issue1251_Test(class [mscorlib]System.Collections.Generic.List`1<class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item> list,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem otherItem) cil managed
@ -2352,13 +2521,13 @@ @@ -2352,13 +2521,13 @@
.size 40
} // end of class '__StaticArrayInitTypeSize=40'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_0000517C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_000053BC
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_0000517C = bytearray (
.data cil I_000053BC = bytearray (
01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00
09 00 00 00 0A 00 00 00)

24
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -383,6 +383,28 @@ namespace ICSharpCode.Decompiler.CSharp @@ -383,6 +383,28 @@ namespace ICSharpCode.Decompiler.CSharp
isExtensionMethodInvocation: method.IsExtensionMethod, isExpandedForm: argumentList.IsExpandedForm));
}
public ExpressionWithResolveResult BuildDictionaryInitializerExpression(OpCode callOpCode, IMethod method,
InitializedObjectResolveResult target, IReadOnlyList<ILInstruction> indices, ILInstruction value = null)
{
ExpectedTargetDetails expectedTargetDetails = new ExpectedTargetDetails { CallOpCode = callOpCode };
var callArguments = new List<ILInstruction>();
callArguments.Add(new LdNull());
callArguments.AddRange(indices);
callArguments.Add(value ?? new Nop());
var argumentList = BuildArgumentList(expectedTargetDetails, target, method, 1, callArguments, null);
var unused = new IdentifierExpression("initializedObject").WithRR(target).WithoutILInstruction();
var assignment = HandleAccessorCall(expectedTargetDetails, method, unused,
argumentList.Arguments.ToList(), argumentList.ArgumentNames);
if (value != null)
return assignment;
return new ExpressionWithResolveResult(((AssignmentExpression)assignment).Left.Detach());
}
private bool IsInterpolatedStringCreation(IMethod method)
{
return method.IsStatic && (
@ -1035,7 +1057,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1035,7 +1057,7 @@ namespace ICSharpCode.Decompiler.CSharp
TranslatedExpression expr;
if (arguments.Count != 0) {
expr = new IndexerExpression(target.Expression, arguments.Select(a => a.Expression))
expr = new IndexerExpression(target.ResolveResult is InitializedObjectResolveResult ? null : target.Expression, arguments.Select(a => a.Expression))
.WithoutILInstruction().WithRR(rr);
} else if (requireTarget) {
expr = new MemberReferenceExpression(target.Expression, method.AccessorOwner.Name)

94
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2010,10 +2010,13 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2010,10 +2010,13 @@ namespace ICSharpCode.Decompiler.CSharp
{
var stloc = block.Instructions.FirstOrDefault() as StLoc;
var final = block.FinalInstruction as LdLoc;
if (stloc == null || final == null || stloc.Variable != final.Variable || stloc.Variable.Kind != VariableKind.InitializerTarget)
// Check basic structure of block
if (stloc == null || final == null || stloc.Variable != final.Variable
|| stloc.Variable.Kind != VariableKind.InitializerTarget)
throw new ArgumentException("given Block is invalid!");
InitializedObjectResolveResult initObjRR;
TranslatedExpression expr;
// Detect type of initializer
switch (stloc.Value) {
case NewObj newObjInst:
initObjRR = new InitializedObjectResolveResult(newObjInst.Method.DeclaringType);
@ -2032,18 +2035,24 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2032,18 +2035,24 @@ namespace ICSharpCode.Decompiler.CSharp
default:
throw new ArgumentException("given Block is invalid!");
}
var elementsStack = new Stack<List<Expression>>();
var elements = new List<Expression>(block.Instructions.Count);
// Build initializer expression
var elementsStack = new Stack<List<TranslatedExpression>>();
var elements = new List<TranslatedExpression>(block.Instructions.Count);
elementsStack.Push(elements);
List<IL.Transforms.AccessPathElement> currentPath = null;
var indexVariables = new Dictionary<ILVariable, ILInstruction>();
foreach (var inst in block.Instructions.Skip(1)) {
// Collect indexer variables (for C# 6 dictionary initializers)
if (inst is StLoc indexStore) {
indexVariables.Add(indexStore.Variable, indexStore.Value);
continue;
}
// Get current path
var info = IL.Transforms.AccessPathElement.GetAccessPath(inst, initObjRR.Type, settings: settings);
// This should not happen, because the IL transform should not create invalid access paths,
// but we leave it here as sanity check.
if (info.Kind == IL.Transforms.AccessPathKind.Invalid) continue;
// Calculate "difference" to previous path
if (currentPath == null) {
currentPath = info.Path;
} else {
@ -2055,25 +2064,38 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2055,25 +2064,38 @@ namespace ICSharpCode.Decompiler.CSharp
var methodElement = currentPath[elementsStack.Count - 1];
var pathElement = currentPath[elementsStack.Count - 2];
var values = elementsStack.Pop();
elementsStack.Peek().Add(MakeInitializerAssignment(methodElement.Member, pathElement, values, indexVariables));
elementsStack.Peek().Add(MakeInitializerAssignment(initObjRR, methodElement, pathElement, values, indexVariables));
}
currentPath = info.Path;
}
// Fill the stack with empty expression lists
while (elementsStack.Count < currentPath.Count)
elementsStack.Push(new List<Expression>());
elementsStack.Push(new List<TranslatedExpression>());
var lastElement = currentPath.Last();
var memberRR = new MemberResolveResult(initObjRR, lastElement.Member);
switch (info.Kind) {
case IL.Transforms.AccessPathKind.Adder:
elementsStack.Peek().Add(new CallBuilder(this, typeSystem, settings).BuildCollectionInitializerExpression(lastElement.OpCode, (IMethod)lastElement.Member, initObjRR, info.Values));
Debug.Assert(lastElement.Member is IMethod);
elementsStack.Peek().Add(
new CallBuilder(this, typeSystem, settings)
.BuildCollectionInitializerExpression(lastElement.OpCode, (IMethod)lastElement.Member, initObjRR, info.Values)
.WithILInstruction(inst)
);
break;
case IL.Transforms.AccessPathKind.Setter:
Debug.Assert(lastElement.Member is IProperty || lastElement.Member is IField);
if (lastElement.Indices?.Length > 0) {
var indexer = new IndexerExpression(null, lastElement.Indices.SelectArray(i => TranslateInitializerIndexerValue(i, indexVariables)))
.WithILInstruction(inst).WithRR(memberRR);
elementsStack.Peek().Add(Assignment(indexer, Translate(info.Values.Single(), typeHint: indexer.Type)));
var property = (IProperty)lastElement.Member;
Debug.Assert(property.IsIndexer);
elementsStack.Peek().Add(
new CallBuilder(this, typeSystem, settings)
.BuildDictionaryInitializerExpression(lastElement.OpCode, property.Setter, initObjRR, GetIndices(lastElement.Indices, indexVariables).ToList(), info.Values.Single())
.WithILInstruction(inst)
);
} else {
var assignment = new NamedExpression(lastElement.Member.Name, Translate(info.Values.Single(), typeHint: memberRR.Type))
var value = Translate(info.Values.Single(), typeHint: memberRR.Type)
.ConvertTo(memberRR.Type, this, allowImplicitConversion: true);
var assignment = new NamedExpression(lastElement.Member.Name, value)
.WithILInstruction(inst).WithRR(memberRR);
elementsStack.Peek().Add(assignment);
}
@ -2084,34 +2106,56 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2084,34 +2106,56 @@ namespace ICSharpCode.Decompiler.CSharp
var methodElement = currentPath[elementsStack.Count - 1];
var pathElement = currentPath[elementsStack.Count - 2];
var values = elementsStack.Pop();
elementsStack.Peek().Add(MakeInitializerAssignment(methodElement.Member, pathElement, values, indexVariables));
elementsStack.Peek().Add(
MakeInitializerAssignment(initObjRR, methodElement, pathElement, values, indexVariables)
);
}
var oce = (ObjectCreateExpression)expr.Expression;
oce.Initializer = new ArrayInitializerExpression(elements);
oce.Initializer = new ArrayInitializerExpression(elements.SelectArray(e => e.Expression));
return expr.WithILInstruction(block);
}
Expression TranslateInitializerIndexerValue(ILInstruction inst, Dictionary<ILVariable, ILInstruction> indexVariables)
IEnumerable<ILInstruction> GetIndices(IEnumerable<ILInstruction> indices, Dictionary<ILVariable, ILInstruction> indexVariables)
{
if (inst is LdLoc ld && indexVariables.TryGetValue(ld.Variable, out var newInst)) {
inst = newInst;
foreach (var inst in indices) {
if (inst is LdLoc ld && indexVariables.TryGetValue(ld.Variable, out var newInst))
yield return newInst;
else
yield return inst;
}
return Translate(inst).Expression;
}
Expression MakeInitializerAssignment(IMember method, IL.Transforms.AccessPathElement member, List<Expression> values, Dictionary<ILVariable, ILInstruction> indexVariables)
TranslatedExpression MakeInitializerAssignment(InitializedObjectResolveResult rr, IL.Transforms.AccessPathElement memberPath,
IL.Transforms.AccessPathElement valuePath, List<TranslatedExpression> values,
Dictionary<ILVariable, ILInstruction> indexVariables)
{
Expression value;
if (values.Count == 1 && !(values[0] is AssignmentExpression || values[0] is NamedExpression) && !(method.SymbolKind == SymbolKind.Method && method.Name == "Add")) {
TranslatedExpression value;
if (memberPath.Member is IMethod method && method.Name == "Add") {
value = new ArrayInitializerExpression(values.Select(v => v.Expression))
.WithRR(new ResolveResult(SpecialType.UnknownType))
.WithoutILInstruction();
} else if (values.Count == 1 && !(values[0].Expression is AssignmentExpression || values[0].Expression is NamedExpression)) {
value = values[0];
} else {
value = new ArrayInitializerExpression(values);
}
if (member.Indices?.Length > 0) {
var index = new IndexerExpression(null, member.Indices.SelectArray(i => Translate(i is LdLoc ld ? indexVariables[ld.Variable] : i).Expression));
return new AssignmentExpression(index, value);
value = new ArrayInitializerExpression(values.Select(v => v.Expression))
.WithRR(new ResolveResult(SpecialType.UnknownType))
.WithoutILInstruction();
}
if (valuePath.Indices?.Length > 0) {
Expression index;
if (memberPath.Member is IProperty property) {
index = new CallBuilder(this, typeSystem, settings)
.BuildDictionaryInitializerExpression(valuePath.OpCode, property.Setter, rr, GetIndices(valuePath.Indices, indexVariables).ToList());
} else {
index = new IndexerExpression(null, GetIndices(valuePath.Indices, indexVariables).Select(i => Translate(i).Expression));
}
return new AssignmentExpression(index, value)
.WithRR(new MemberResolveResult(rr, memberPath.Member))
.WithoutILInstruction();
} else {
return new NamedExpression(member.Member.Name, value);
return new NamedExpression(valuePath.Member.Name, value)
.WithRR(new MemberResolveResult(rr, memberPath.Member))
.WithoutILInstruction();
}
}

9
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -69,7 +69,14 @@ namespace ICSharpCode.Decompiler.CSharp @@ -69,7 +69,14 @@ namespace ICSharpCode.Decompiler.CSharp
public IType Type {
get { return ResolveResult.Type; }
}
internal ExpressionWithResolveResult(Expression expression)
{
Debug.Assert(expression != null);
this.Expression = expression;
this.ResolveResult = expression.Annotation<ResolveResult>() ?? ErrorResolveResult.UnknownError;
}
internal ExpressionWithResolveResult(Expression expression, ResolveResult resolveResult)
{
Debug.Assert(expression != null && resolveResult != null);

Loading…
Cancel
Save