Skip to content

Commit b1049a4

Browse files
committed
Fix issues
- not every ctor has ret at the end - not every catch block has leave-to-ret structure
1 parent a80a6cf commit b1049a4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Weaver/Xtensive.Orm.Weaver/Tasks/ImplementInitializablePatternTask.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public override ActionResult Execute(ProcessorContext context)
2020
{
2121
var body = constructor.Body;
2222
var il = body.GetILProcessor();
23-
var originalLastRet = body.Instructions.Reverse().First(i => i != null && i.OpCode.Code == Code.Ret);
24-
23+
var originalLastRet = body.Instructions.Reverse().FirstOrDefault(i => i != null && i.OpCode.Code == Code.Ret);
2524
var leavePlaceholder = il.Create(OpCodes.Nop);
2625

2726
var initializeCall = EmitInitializeCall(context, il);
@@ -71,7 +70,7 @@ private void ReplaceRetWithBr(ILProcessor il, Instruction start, Instruction end
7170
private void FixCatchLeave(Instruction start, Instruction end, Instruction oldRetTarget, Instruction newTarget)
7271
{
7372
var current = start;
74-
while (current != end) {
73+
while (current != end && current != null) {
7574
var next = current.Next;
7675
var code = current.OpCode.Code;
7776
if ((code == Code.Leave || code == Code.Leave_S) && current.Operand == oldRetTarget) {

0 commit comments

Comments
 (0)