Skip to content

Commit

Permalink
#2622: Fix crash in ExpressionBuilder when decompiling object initial…
Browse files Browse the repository at this point in the history
…izer composed of readonly properties.
  • Loading branch information
siegfriedpammer committed Feb 6, 2022
1 parent 07bedd4 commit 41c99e4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,43 @@ public static void Bug270_NestedInitialisers()

}

#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
{
Expand Down
13 changes: 2 additions & 11 deletions ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3305,18 +3305,9 @@ TranslatedExpression MakeInitializerAssignment(InitializedObjectResolveResult rr
}
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
Expand Down

0 comments on commit 41c99e4

Please sign in to comment.