Browse Source

Fix #2104: Check field name of backing field when attempting to transform to an auto property.

pull/2126/head
Siegfried Pammer 5 years ago
parent
commit
15028b3669
  1. 2
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs
  3. 20
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue2104.cs
  4. 81
      ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue2104.il
  5. 2
      ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

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

@ -66,6 +66,7 @@ @@ -66,6 +66,7 @@
<None Include="TestCases\ILPretty\Issue1681.il" />
<None Include="TestCases\ILPretty\Issue1922.il" />
<None Include="TestCases\ILPretty\Issue1918.il" />
<None Include="TestCases\ILPretty\Issue2104.il" />
<None Include="TestCases\ILPretty\WeirdEnums.il" />
<None Include="TestCases\ILPretty\ConstantBlobs.il" />
<None Include="TestCases\ILPretty\CS1xSwitch_Debug.il" />
@ -94,6 +95,7 @@ @@ -94,6 +95,7 @@
<Compile Include="TestCases\Correctness\DeconstructionTests.cs" />
<Compile Include="TestCases\Correctness\StringConcat.cs" />
<Compile Include="TestCases\Pretty\DeconstructionTests.cs" />
<Compile Include="TestCases\ILPretty\Issue2104.cs" />
<Compile Include="TestCases\Pretty\SwitchExpressions.cs" />
<None Include="TestCases\Pretty\NativeInts.cs" />
<None Include="TestCases\ILPretty\CallIndirect.cs" />

6
ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

@ -178,6 +178,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -178,6 +178,12 @@ namespace ICSharpCode.Decompiler.Tests
Run();
}
[Test]
public void Issue2104()
{
Run();
}
[Test]
public void ConstantBlobs()
{

20
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue2104.cs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
using System.Runtime.CompilerServices;
namespace ICSharpCode.Decompiler.Tests.TestCases.ILPretty
{
internal class Issue2104
{
[CompilerGenerated]
private readonly string text;
public string Text {
[CompilerGenerated]
get {
return text;
}
}
public Issue2104(string text)
{
this.text = text;
}
}
}

81
ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue2104.il

@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
.assembly issue2104
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
01 00 08 00 00 00 00 00
)
.custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = (
01 00 01 00 54 02 16 57 72 61 70 4e 6f 6e 45 78
63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
)
.custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = (
01 00 07 01 00 00 00 00
)
.hash algorithm 0x00008004 // SHA1
.ver 0:0:0:0
}
.module issue2104.exe
// MVID: {A7498FA1-F4D7-486E-A872-3DC0CAFD87E2}
.imagebase 0x10000000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WindowsCui
.corflags 0x00000001 // ILOnly
.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = (
01 00 00 00
)
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue2104
extends [mscorlib]System.Object
{
// Fields
.field private initonly string 'text'
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Methods
.method public hidebysig specialname
instance string get_Text () cil managed
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Method begins at RVA 0x2074
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue2104::text
IL_0006: ret
} // end of method ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue2104::get_Text
.method public hidebysig specialname rtspecialname
instance void .ctor (
string text
) cil managed
{
// Method begins at RVA 0x207c
// Code size 14 (0xe)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue2104::'text'
IL_000d: ret
} // end of method ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue2104::.ctor
// Properties
.property instance string Text()
{
.get instance string ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue2104::get_Text()
}
} // end of class ICSharpCode.Decompiler.Tests.TestCases.ILPretty.Issue2104

2
ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

@ -586,7 +586,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -586,7 +586,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
field = m2.Get<AstNode>("fieldReference").Single().GetSymbol() as IField;
}
}
if (field == null)
if (field == null || !(field.Name.StartsWith("<") && field.Name.EndsWith(">k__BackingField")))
return null;
if (propertyDeclaration.Setter.HasModifier(Modifiers.Readonly))
return null;

Loading…
Cancel
Save