Browse Source

Add test case for simple records.

pull/2251/head
Daniel Grunwald 4 years ago
parent
commit
a960216d5f
  1. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  3. 35
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Records.cs
  4. 4
      ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

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

@ -105,6 +105,7 @@ @@ -105,6 +105,7 @@
<Compile Include="TestAssemblyResolver.cs" />
<Compile Include="TestCases\Correctness\DeconstructionTests.cs" />
<Compile Include="TestCases\Correctness\StringConcat.cs" />
<None Include="TestCases\Pretty\Records.cs" />
<Compile Include="TestCases\VBPretty\Issue2192.cs" />
<Compile Include="Util\FileUtilityTests.cs" />
<None Include="TestCases\Pretty\FunctionPointers.cs" />

6
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -404,6 +404,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -404,6 +404,12 @@ namespace ICSharpCode.Decompiler.Tests
RunForLibrary(cscOptions: cscOptions | CompilerOptions.Preview);
}
[Test]
public void Records([ValueSource(nameof(roslynLatestOnlyOptions))] CompilerOptions cscOptions)
{
RunForLibrary(cscOptions: cscOptions | CompilerOptions.Preview);
}
[Test]
public void NullPropagation([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions)
{

35
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Records.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
public record Empty
{
}
public record Properties
{
public int A {
get;
set;
}
public int B {
get;
}
public int C => 43;
public object O {
get;
set;
}
public string S {
get;
set;
}
public dynamic D {
get;
set;
}
public Properties()
{
B = 42;
}
}
}

4
ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

@ -284,7 +284,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -284,7 +284,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (!valueInst.MatchLdFld(out var rhsTarget, out var rhsField))
return false;
if (!rhsTarget.MatchLdThis())
if (!rhsTarget.MatchLdLoc(other))
return false;
if (!rhsField.Equals(field))
return false;
@ -824,6 +824,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -824,6 +824,8 @@ namespace ICSharpCode.Decompiler.CSharp
// Remove the last couple transforms -- we don't need variable names etc. here
int lastBlockTransform = transforms.FindLastIndex(t => t is BlockILTransform);
transforms.RemoveRange(lastBlockTransform + 1, transforms.Count - (lastBlockTransform + 1));
// Use CombineExitsTransform so that "return other != null && ...;" is a single statement even in release builds
transforms.Add(new CombineExitsTransform());
il.RunTransforms(transforms,
new ILTransformContext(il, typeSystem, debugInfo: null, settings) {
CancellationToken = cancellationToken

Loading…
Cancel
Save