Browse Source

#2622: Fix crash in ExpressionBuilder when decompiling object initializer composed of readonly properties.

pull/2626/head v7.2-preview4
Siegfried Pammer 3 years ago
parent
commit
41c99e4727
  1. 36
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs
  2. 13
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

36
ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs

@ -391,7 +391,43 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -391,7 +391,43 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
#if CS60
class Issue2622a
{
public class C
{
public ServiceHost M()
{
return new ServiceHost(typeof(EWSService), null) {
Description = { Endpoints = { [0] = { Behaviors = { new EwsWebHttpBehavior() } } } }
};
}
}
class EWSService { }
public class ServiceHost
{
public ServiceHost(Type type, object x) { }
public Descr Description { get; }
}
public class Descr
{
public List<EP> Endpoints { get; }
}
public class EP
{
public List<Beh> Behaviors { get; }
}
public abstract class Beh { }
public class EwsWebHttpBehavior : Beh { }
}
#endif
class Issue855
{

13
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -3305,18 +3305,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -3305,18 +3305,9 @@ namespace ICSharpCode.Decompiler.CSharp
}
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));
}
Expression index = new IndexerExpression(null, GetIndices(valuePath.Indices, indexVariables).Select(i => Translate(i).Expression));
return new AssignmentExpression(index, value)
.WithRR(new MemberResolveResult(rr, memberPath.Member))
.WithRR(new MemberResolveResult(rr, valuePath.Member))
.WithoutILInstruction();
}
else

Loading…
Cancel
Save