Skip to content

Commit 41c99e4

Browse files
#2622: Fix crash in ExpressionBuilder when decompiling object initializer composed of readonly properties.
1 parent 07bedd4 commit 41c99e4

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,43 @@ public static void Bug270_NestedInitialisers()
391391

392392
}
393393

394+
#if CS60
395+
class Issue2622a
396+
{
397+
public class C
398+
{
399+
public ServiceHost M()
400+
{
401+
return new ServiceHost(typeof(EWSService), null) {
402+
Description = { Endpoints = { [0] = { Behaviors = { new EwsWebHttpBehavior() } } } }
403+
};
404+
}
405+
}
406+
407+
class EWSService { }
408+
409+
public class ServiceHost
410+
{
411+
public ServiceHost(Type type, object x) { }
412+
413+
public Descr Description { get; }
414+
}
415+
416+
public class Descr
417+
{
418+
public List<EP> Endpoints { get; }
419+
}
420+
421+
public class EP
422+
{
423+
public List<Beh> Behaviors { get; }
424+
}
425+
426+
public abstract class Beh { }
394427

428+
public class EwsWebHttpBehavior : Beh { }
429+
}
430+
#endif
395431

396432
class Issue855
397433
{

ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,18 +3305,9 @@ TranslatedExpression MakeInitializerAssignment(InitializedObjectResolveResult rr
33053305
}
33063306
if (valuePath.Indices?.Length > 0)
33073307
{
3308-
Expression index;
3309-
if (memberPath.Member is IProperty property)
3310-
{
3311-
index = new CallBuilder(this, typeSystem, settings)
3312-
.BuildDictionaryInitializerExpression(valuePath.OpCode, property.Setter, rr, GetIndices(valuePath.Indices, indexVariables).ToList());
3313-
}
3314-
else
3315-
{
3316-
index = new IndexerExpression(null, GetIndices(valuePath.Indices, indexVariables).Select(i => Translate(i).Expression));
3317-
}
3308+
Expression index = new IndexerExpression(null, GetIndices(valuePath.Indices, indexVariables).Select(i => Translate(i).Expression));
33183309
return new AssignmentExpression(index, value)
3319-
.WithRR(new MemberResolveResult(rr, memberPath.Member))
3310+
.WithRR(new MemberResolveResult(rr, valuePath.Member))
33203311
.WithoutILInstruction();
33213312
}
33223313
else

0 commit comments

Comments
 (0)