Skip to content

Commit 88b2c43

Browse files
committed
Address PR review feedback
1 parent 45efc73 commit 88b2c43

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,15 @@ public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
271271
if (typeDeclaration.HasPrimaryConstructor)
272272
{
273273
inPrimaryConstructor = true;
274-
typeDeclaration.PrimaryConstructorParameters.AcceptVisitor(this);
275-
inPrimaryConstructor = false;
274+
275+
try
276+
{
277+
typeDeclaration.PrimaryConstructorParameters.AcceptVisitor(this);
278+
}
279+
finally
280+
{
281+
inPrimaryConstructor = false;
282+
}
276283
}
277284

278285
var previousResolver = resolver;
@@ -294,6 +301,11 @@ public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
294301

295302
public override void VisitParameterDeclaration(ParameterDeclaration parameterDeclaration)
296303
{
304+
// Parameters of primary constructors are visited separately from the rest of the
305+
// type declaration since their types are at the same scope as the type declaration
306+
// and so need to use the outer resolver. This check ensures that the visitor only
307+
// runs once per parameter since their AstNodes will get revisited by the call to
308+
// `base.VisitTypeDeclaration(typeDeclaration)` in `VisitTypeDeclaration` above.
297309
if (inPrimaryConstructor || parameterDeclaration.Parent is not TypeDeclaration)
298310
base.VisitParameterDeclaration(parameterDeclaration);
299311
}

0 commit comments

Comments
 (0)