Browse Source

Fix #1345: Do not construct object initializer, if property or field in access path is not writable.

pull/1360/head
Siegfried Pammer 7 years ago
parent
commit
77c1dbab8a
  1. 37
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs
  2. 119
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il
  3. 100
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il
  4. 140
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il
  5. 173
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il
  6. 11
      ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

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

@ -241,6 +241,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -241,6 +241,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
}
}
public class OtherItem2
{
public readonly OtherItem Data;
public OtherItem Data2 {
get;
private set;
}
#if CS60
public OtherItem Data3 {
get;
}
#endif
}
// Helper methods used to ensure initializers used within expressions work correctly
private static void X(object a, object b)
{
@ -761,5 +776,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests @@ -761,5 +776,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests
{
throw new NotImplementedException();
}
public OtherItem2 Issue1345()
{
OtherItem2 otherItem = new OtherItem2();
otherItem.Data.Nullable = 3m;
return otherItem;
}
public OtherItem2 Issue1345b()
{
OtherItem2 otherItem = new OtherItem2();
otherItem.Data2.Nullable = 3m;
return otherItem;
}
#if CS60
public OtherItem2 Issue1345c()
{
OtherItem2 otherItem = new OtherItem2();
otherItem.Data3.Nullable = 3m;
return otherItem;
}
#endif
}
}

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

@ -937,8 +937,8 @@ @@ -937,8 +937,8 @@
.property instance string Text()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Text()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Text(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Text()
} // end of property Item::Text
.property instance valuetype [mscorlib]System.Decimal
Value()
@ -954,13 +954,13 @@ @@ -954,13 +954,13 @@
} // end of property Item::Value2
.property instance string Value3()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value3()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value3(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value3()
} // end of property Item::Value3
.property instance string 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()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value4(string)
} // end of property Item::Value4
.property instance string Value5()
{
@ -969,8 +969,8 @@ @@ -969,8 +969,8 @@
} // end of property Item::Value5
.property instance string 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()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value6(string)
} // end of property Item::Value6
} // end of class Item
@ -1176,26 +1176,26 @@ @@ -1176,26 +1176,26 @@
.property instance valuetype [mscorlib]System.Decimal
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()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Value(valuetype [mscorlib]System.Decimal)
} // end of property OtherItem::Value
.property instance valuetype [mscorlib]System.Decimal
Value2()
{
.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)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Value2()
} // end of property OtherItem::Value2
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
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()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
} // end of property OtherItem::Nullable
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable2()
{
.get instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Nullable2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable2(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_Nullable2()
} // end of property OtherItem::Nullable2
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable3()
@ -1211,6 +1211,59 @@ @@ -1211,6 +1211,59 @@
} // end of property OtherItem::Nullable4
} // end of class OtherItem
.class auto ansi nested public beforefieldinit OtherItem2
extends [mscorlib]System.Object
{
.field public initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem Data
.field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem '<Data2>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname
instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
get_Data2() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 11 (0xb)
.maxstack 1
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem V_0)
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data2>k__BackingField'
IL_0006: stloc.0
IL_0007: br.s IL_0009
IL_0009: ldloc.0
IL_000a: ret
} // end of method OtherItem2::get_Data2
.method private hidebysig specialname
instance void set_Data2(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem 'value') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data2>k__BackingField'
IL_0007: ret
} // end of method OtherItem2::set_Data2
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method OtherItem2::.ctor
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
Data2()
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::set_Data2(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem)
} // end of property OtherItem2::Data2
} // end of class OtherItem2
.field private static class [mscorlib]System.EventHandler 'CS$<>9__CachedAnonymousMethodDelegate9'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private static class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> 'CS$<>9__CachedAnonymousMethodDelegate1d'
@ -2507,6 +2560,56 @@ @@ -2507,6 +2560,56 @@
IL_0006: throw
} // end of method TestCases::Data_TestEvent
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345() cil managed
{
// Code size 36 (0x24)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_0,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_1)
IL_0000: nop
IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::Data
IL_000d: ldc.i4.3
IL_000e: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0013: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0018: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001d: nop
IL_001e: ldloc.0
IL_001f: stloc.1
IL_0020: br.s IL_0022
IL_0022: ldloc.1
IL_0023: ret
} // end of method TestCases::Issue1345
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345b() cil managed
{
// Code size 36 (0x24)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_0,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_1)
IL_0000: nop
IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data2()
IL_000d: ldc.i4.3
IL_000e: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0013: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0018: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001d: nop
IL_001e: ldloc.0
IL_001f: stloc.1
IL_0020: br.s IL_0022
IL_0022: ldloc.1
IL_0023: ret
} // end of method TestCases::Issue1345b
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

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

@ -817,8 +817,8 @@ @@ -817,8 +817,8 @@
.property instance string Text()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Text()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Text(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Text()
} // end of property Item::Text
.property instance valuetype [mscorlib]System.Decimal
Value()
@ -834,13 +834,13 @@ @@ -834,13 +834,13 @@
} // end of property Item::Value2
.property instance string Value3()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value3()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value3(string)
.get instance string ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::get_Value3()
} // end of property Item::Value3
.property instance string 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()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value4(string)
} // end of property Item::Value4
.property instance string Value5()
{
@ -849,8 +849,8 @@ @@ -849,8 +849,8 @@
} // end of property Item::Value5
.property instance string 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()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Item::set_Value6(string)
} // end of property Item::Value6
} // end of class Item
@ -1026,26 +1026,26 @@ @@ -1026,26 +1026,26 @@
.property instance valuetype [mscorlib]System.Decimal
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()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Value(valuetype [mscorlib]System.Decimal)
} // end of property OtherItem::Value
.property instance valuetype [mscorlib]System.Decimal
Value2()
{
.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)
.get instance valuetype [mscorlib]System.Decimal ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Value2()
} // end of property OtherItem::Value2
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
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()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
} // end of property OtherItem::Nullable
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable2()
{
.get instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::get_Nullable2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable2(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_Nullable2()
} // end of property OtherItem::Nullable2
.property instance valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>
Nullable3()
@ -1061,6 +1061,54 @@ @@ -1061,6 +1061,54 @@
} // end of property OtherItem::Nullable4
} // end of class OtherItem
.class auto ansi nested public beforefieldinit OtherItem2
extends [mscorlib]System.Object
{
.field public initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem Data
.field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem '<Data2>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname
instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
get_Data2() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data2>k__BackingField'
IL_0006: ret
} // end of method OtherItem2::get_Data2
.method private hidebysig specialname
instance void set_Data2(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem 'value') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data2>k__BackingField'
IL_0007: ret
} // end of method OtherItem2::set_Data2
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method OtherItem2::.ctor
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
Data2()
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::set_Data2(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem)
} // end of property OtherItem2::Data2
} // end of class OtherItem2
.field private static class [mscorlib]System.EventHandler 'CS$<>9__CachedAnonymousMethodDelegate9'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private static class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> 'CS$<>9__CachedAnonymousMethodDelegate1d'
@ -2141,6 +2189,42 @@ @@ -2141,6 +2189,42 @@
IL_0005: throw
} // end of method TestCases::Data_TestEvent
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345() cil managed
{
// Code size 30 (0x1e)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::Data
IL_000c: ldc.i4.3
IL_000d: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0012: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0017: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001c: ldloc.0
IL_001d: ret
} // end of method TestCases::Issue1345
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345b() cil managed
{
// Code size 30 (0x1e)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_0)
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data2()
IL_000c: ldc.i4.3
IL_000d: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0012: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0017: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001c: ldloc.0
IL_001d: ret
} // end of method TestCases::Issue1345b
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{

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

@ -1068,13 +1068,80 @@ @@ -1068,13 +1068,80 @@
} // end of property OtherItem::Nullable4
} // end of class OtherItem
.class auto ansi nested public beforefieldinit OtherItem2
extends [mscorlib]System.Object
{
.field public initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem Data
.field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem '<Data2>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem '<Data3>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname
instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
get_Data2() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data2>k__BackingField'
IL_0006: ret
} // end of method OtherItem2::get_Data2
.method private hidebysig specialname
instance void set_Data2(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem 'value') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data2>k__BackingField'
IL_0007: ret
} // end of method OtherItem2::set_Data2
.method public hidebysig specialname
instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
get_Data3() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data3>k__BackingField'
IL_0006: ret
} // end of method OtherItem2::get_Data3
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
} // end of method OtherItem2::.ctor
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
Data2()
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::set_Data2(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem)
} // end of property OtherItem2::Data2
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
Data3()
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data3()
} // end of property OtherItem2::Data3
} // end of class OtherItem2
.class auto ansi serializable sealed nested private beforefieldinit '<>c'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' '<>9'
.field public static class [mscorlib]System.EventHandler '<>9__32_0'
.field public static class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> '<>9__52_0'
.field public static class [mscorlib]System.EventHandler '<>9__33_0'
.field public static class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> '<>9__53_0'
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
@ -1096,17 +1163,17 @@ @@ -1096,17 +1163,17 @@
} // end of method '<>c'::.ctor
.method assembly hidebysig instance void
'<NotAnObjectInitializerWithEvent>b__32_0'(object '<p0>',
'<NotAnObjectInitializerWithEvent>b__33_0'(object '<p0>',
class [mscorlib]System.EventArgs '<p1>') cil managed
{
// Code size 6 (0x6)
.maxstack 8
IL_0000: call void [mscorlib]System.Console::WriteLine()
IL_0005: ret
} // end of method '<>c'::'<NotAnObjectInitializerWithEvent>b__32_0'
} // end of method '<>c'::'<NotAnObjectInitializerWithEvent>b__33_0'
.method assembly hidebysig instance bool
'<Bug270_NestedInitialisers>b__52_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed
'<Bug270_NestedInitialisers>b__53_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed
{
// Code size 17 (0x11)
.maxstack 8
@ -1116,7 +1183,7 @@ @@ -1116,7 +1183,7 @@
IL_000b: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_0010: ret
} // end of method '<>c'::'<Bug270_NestedInitialisers>b__52_0'
} // end of method '<>c'::'<Bug270_NestedInitialisers>b__53_0'
} // end of class '<>c'
@ -1525,18 +1592,18 @@ @@ -1525,18 +1592,18 @@
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::.ctor()
IL_0005: stloc.0
IL_0006: ldloc.0
IL_0007: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__32_0'
IL_0007: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__33_0'
IL_000c: dup
IL_000d: brtrue.s IL_0026
IL_000f: pop
IL_0010: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9'
IL_0015: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<NotAnObjectInitializerWithEvent>b__32_0'(object,
IL_0015: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<NotAnObjectInitializerWithEvent>b__33_0'(object,
class [mscorlib]System.EventArgs)
IL_001b: newobj instance void [mscorlib]System.EventHandler::.ctor(object,
native int)
IL_0020: dup
IL_0021: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__32_0'
IL_0021: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__33_0'
IL_0026: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::add_TestEvent(class [mscorlib]System.EventHandler)
IL_002b: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
IL_0030: ldloc.0
@ -2004,17 +2071,17 @@ @@ -2004,17 +2071,17 @@
IL_0033: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo)
IL_0038: dup
IL_0039: ldloc.0
IL_003a: ldsfld class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__52_0'
IL_003a: ldsfld class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__53_0'
IL_003f: dup
IL_0040: brtrue.s IL_0059
IL_0042: pop
IL_0043: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9'
IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<Bug270_NestedInitialisers>b__52_0'(class [mscorlib]System.Globalization.NumberFormatInfo)
IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<Bug270_NestedInitialisers>b__53_0'(class [mscorlib]System.Globalization.NumberFormatInfo)
IL_004e: newobj instance void class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool>::.ctor(object,
native int)
IL_0053: dup
IL_0054: stsfld class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__52_0'
IL_0054: stsfld class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__53_0'
IL_0059: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0> [System.Core]System.Linq.Enumerable::Where<class [mscorlib]System.Globalization.NumberFormatInfo>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,bool>)
IL_005e: call !!0 [System.Core]System.Linq.Enumerable::First<class [mscorlib]System.Globalization.NumberFormatInfo>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>)
@ -2228,6 +2295,51 @@ @@ -2228,6 +2295,51 @@
IL_0005: throw
} // end of method TestCases::Data_TestEvent
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345() cil managed
{
// Code size 28 (0x1c)
.maxstack 8
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0005: dup
IL_0006: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::Data
IL_000b: ldc.i4.3
IL_000c: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0011: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0016: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001b: ret
} // end of method TestCases::Issue1345
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345b() cil managed
{
// Code size 28 (0x1c)
.maxstack 8
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0005: dup
IL_0006: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data2()
IL_000b: ldc.i4.3
IL_000c: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0011: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0016: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001b: ret
} // end of method TestCases::Issue1345b
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345c() cil managed
{
// Code size 28 (0x1c)
.maxstack 8
IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0005: dup
IL_0006: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data3()
IL_000b: ldc.i4.3
IL_000c: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0011: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0016: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001b: ret
} // end of method TestCases::Issue1345c
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -2251,13 +2363,13 @@ @@ -2251,13 +2363,13 @@
.size 40
} // end of class '__StaticArrayInitTypeSize=40'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00005180
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00005360
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_00005180 = bytearray (
.data cil I_00005360 = 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)

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

@ -1131,13 +1131,83 @@ @@ -1131,13 +1131,83 @@
} // end of property OtherItem::Nullable4
} // end of class OtherItem
.class auto ansi nested public beforefieldinit OtherItem2
extends [mscorlib]System.Object
{
.field public initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem Data
.field private class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem '<Data2>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field private initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem '<Data3>k__BackingField'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
get_Data2() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data2>k__BackingField'
IL_0006: ret
} // end of method OtherItem2::get_Data2
.method private hidebysig specialname
instance void set_Data2(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem 'value') cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data2>k__BackingField'
IL_0007: ret
} // end of method OtherItem2::set_Data2
.method public hidebysig specialname
instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
get_Data3() cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::'<Data3>k__BackingField'
IL_0006: ret
} // end of method OtherItem2::get_Data3
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method OtherItem2::.ctor
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
Data2()
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data2()
.set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::set_Data2(class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem)
} // end of property OtherItem2::Data2
.property instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem
Data3()
{
.get instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data3()
} // end of property OtherItem2::Data3
} // end of class OtherItem2
.class auto ansi serializable sealed nested private beforefieldinit '<>c'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' '<>9'
.field public static class [mscorlib]System.EventHandler '<>9__32_0'
.field public static class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> '<>9__52_0'
.field public static class [mscorlib]System.EventHandler '<>9__33_0'
.field public static class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> '<>9__53_0'
.method private hidebysig specialname rtspecialname static
void .cctor() cil managed
{
@ -1160,7 +1230,7 @@ @@ -1160,7 +1230,7 @@
} // end of method '<>c'::.ctor
.method assembly hidebysig instance void
'<NotAnObjectInitializerWithEvent>b__32_0'(object '<p0>',
'<NotAnObjectInitializerWithEvent>b__33_0'(object '<p0>',
class [mscorlib]System.EventArgs '<p1>') cil managed
{
// Code size 8 (0x8)
@ -1169,10 +1239,10 @@ @@ -1169,10 +1239,10 @@
IL_0001: call void [mscorlib]System.Console::WriteLine()
IL_0006: nop
IL_0007: ret
} // end of method '<>c'::'<NotAnObjectInitializerWithEvent>b__32_0'
} // end of method '<>c'::'<NotAnObjectInitializerWithEvent>b__33_0'
.method assembly hidebysig instance bool
'<Bug270_NestedInitialisers>b__52_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed
'<Bug270_NestedInitialisers>b__53_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed
{
// Code size 17 (0x11)
.maxstack 8
@ -1182,7 +1252,7 @@ @@ -1182,7 +1252,7 @@
IL_000b: call bool [mscorlib]System.String::op_Equality(string,
string)
IL_0010: ret
} // end of method '<>c'::'<Bug270_NestedInitialisers>b__52_0'
} // end of method '<>c'::'<Bug270_NestedInitialisers>b__53_0'
} // end of class '<>c'
@ -1709,18 +1779,18 @@ @@ -1709,18 +1779,18 @@
IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__32_0'
IL_0008: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__33_0'
IL_000d: dup
IL_000e: brtrue.s IL_0027
IL_0010: pop
IL_0011: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9'
IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<NotAnObjectInitializerWithEvent>b__32_0'(object,
IL_0016: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<NotAnObjectInitializerWithEvent>b__33_0'(object,
class [mscorlib]System.EventArgs)
IL_001c: newobj instance void [mscorlib]System.EventHandler::.ctor(object,
native int)
IL_0021: dup
IL_0022: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__32_0'
IL_0022: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__33_0'
IL_0027: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/Data::add_TestEvent(class [mscorlib]System.EventHandler)
IL_002c: nop
IL_002d: call object ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases::Y()
@ -2281,17 +2351,17 @@ @@ -2281,17 +2351,17 @@
IL_003b: nop
IL_003c: dup
IL_003d: ldloc.0
IL_003e: ldsfld class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__52_0'
IL_003e: ldsfld class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__53_0'
IL_0043: dup
IL_0044: brtrue.s IL_005d
IL_0046: pop
IL_0047: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9'
IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<Bug270_NestedInitialisers>b__52_0'(class [mscorlib]System.Globalization.NumberFormatInfo)
IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<Bug270_NestedInitialisers>b__53_0'(class [mscorlib]System.Globalization.NumberFormatInfo)
IL_0052: newobj instance void class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool>::.ctor(object,
native int)
IL_0057: dup
IL_0058: stsfld class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__52_0'
IL_0058: stsfld class [mscorlib]System.Func`2<class [mscorlib]System.Globalization.NumberFormatInfo,bool> ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/'<>c'::'<>9__53_0'
IL_005d: call class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0> [System.Core]System.Linq.Enumerable::Where<class [mscorlib]System.Globalization.NumberFormatInfo>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,
class [mscorlib]System.Func`2<!!0,bool>)
IL_0062: call !!0 [System.Core]System.Linq.Enumerable::First<class [mscorlib]System.Globalization.NumberFormatInfo>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>)
@ -2551,6 +2621,81 @@ @@ -2551,6 +2621,81 @@
IL_0006: throw
} // end of method TestCases::Data_TestEvent
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345() cil managed
{
// Code size 36 (0x24)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_0,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_1)
IL_0000: nop
IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::Data
IL_000d: ldc.i4.3
IL_000e: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0013: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0018: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001d: nop
IL_001e: ldloc.0
IL_001f: stloc.1
IL_0020: br.s IL_0022
IL_0022: ldloc.1
IL_0023: ret
} // end of method TestCases::Issue1345
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345b() cil managed
{
// Code size 36 (0x24)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_0,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_1)
IL_0000: nop
IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data2()
IL_000d: ldc.i4.3
IL_000e: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0013: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0018: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001d: nop
IL_001e: ldloc.0
IL_001f: stloc.1
IL_0020: br.s IL_0022
IL_0022: ldloc.1
IL_0023: ret
} // end of method TestCases::Issue1345b
.method public hidebysig instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2
Issue1345c() cil managed
{
// Code size 36 (0x24)
.maxstack 2
.locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_0,
class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2 V_1)
IL_0000: nop
IL_0001: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::.ctor()
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: callvirt instance class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem2::get_Data3()
IL_000d: ldc.i4.3
IL_000e: newobj instance void [mscorlib]System.Decimal::.ctor(int32)
IL_0013: newobj instance void valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>::.ctor(!0)
IL_0018: callvirt instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests.TestCases/OtherItem::set_Nullable(valuetype [mscorlib]System.Nullable`1<valuetype [mscorlib]System.Decimal>)
IL_001d: nop
IL_001e: ldloc.0
IL_001f: stloc.1
IL_0020: br.s IL_0022
IL_0022: ldloc.1
IL_0023: ret
} // end of method TestCases::Issue1345c
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -2575,13 +2720,13 @@ @@ -2575,13 +2720,13 @@
.size 40
} // end of class '__StaticArrayInitTypeSize=40'
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_0000545C
.field static assembly initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=40' E0D2592373A0C161E56E266306CD8405CD719D19 at I_00005694
} // end of class '<PrivateImplementationDetails>'
// =============================================================
.data cil I_0000545C = bytearray (
.data cil I_00005694 = 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)

11
ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

@ -265,6 +265,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -265,6 +265,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
instruction = call.Arguments[0];
if (method.IsAccessor) {
var property = method.AccessorOwner as IProperty;
if (!property.CanSet || !(property.Accessibility == property.Setter.Accessibility || IsAccessorAccessible(property.Setter, resolveContext))) goto default;
var isGetter = method.Equals(property?.Getter);
var indices = call.Arguments.Skip(1).Take(call.Arguments.Count - (isGetter ? 1 : 2)).ToArray();
if (indices.Length > 0 && !settings.DictionaryInitializers) goto default;
@ -292,7 +293,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -292,7 +293,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
}
break;
case LdObj ldobj: {
if (ldobj.Target is LdFlda ldflda) {
if (ldobj.Target is LdFlda ldflda && !ldflda.Field.IsReadOnly) {
path.Insert(0, new AccessPathElement(ldobj.OpCode, ldflda.Field));
instruction = ldflda.Target;
break;
@ -334,6 +335,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -334,6 +335,14 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return (kind, path, values, target);
}
private static bool IsAccessorAccessible(IMethod setter, CSharpTypeResolveContext resolveContext)
{
if (resolveContext == null)
return true;
var lookup = new MemberLookup(resolveContext.CurrentTypeDefinition, resolveContext.CurrentModule);
return lookup.IsAccessible(setter, allowProtectedAccess: setter.DeclaringTypeDefinition == resolveContext.CurrentTypeDefinition);
}
static bool IsMethodApplicable(IMethod method, IReadOnlyList<ILInstruction> arguments, IType rootType, CSharpTypeResolveContext resolveContext, DecompilerSettings settings)
{
if (method.IsStatic && !method.IsExtensionMethod)

Loading…
Cancel
Save