Skip to content

Commit 73e9771

Browse files
Fix #2269: LocalFunctionDecompiler misplaces nested local functions in ctors
1 parent 4994238 commit 73e9771

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ICSharpCode.Decompiler/IL/Transforms/LocalFunctionDecompiler.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,20 @@ private void DetermineCaptureAndDeclarationScopes(Dictionary<MethodDefinitionHan
142142
{
143143
DetermineCaptureAndDeclarationScope(info, useSite);
144144

145-
if (context.Function.Method.IsConstructor && localFunction.DeclarationScope == null)
145+
if (context.Function.Method.IsConstructor)
146146
{
147-
localFunction.DeclarationScope = BlockContainer.FindClosestContainer(useSite);
147+
if (localFunction.DeclarationScope == null)
148+
{
149+
localFunction.DeclarationScope = BlockContainer.FindClosestContainer(useSite);
150+
}
151+
else
152+
{
153+
localFunction.DeclarationScope = FindCommonAncestorInstruction<BlockContainer>(useSite, localFunction.DeclarationScope);
154+
if (localFunction.DeclarationScope == null)
155+
{
156+
localFunction.DeclarationScope = (BlockContainer)context.Function.Body;
157+
}
158+
}
148159
}
149160
}
150161

0 commit comments

Comments
 (0)