Browse Source

Remove redundant AnonymousMethodExpression.HasParameterList

The decompiler never emits "delegate () {}" (an explicit empty parameter
list) -- it produces "delegate {}" when there are no parameters and
"delegate (...) {}" when there are -- so HasParameterList always equalled
Parameters.Any(). Drop the property, its backing field and the two setter
calls, and read Parameters.Any() directly at the printer and the
resolve-result builder.

Assisted-by: Claude:claude-opus-4-8:Claude Code
pull/3807/head
Siegfried Pammer 3 weeks ago committed by Siegfried Pammer
parent
commit
30f070558f
  1. 4
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  3. 8
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs

4
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2428,7 +2428,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2428,7 +2428,6 @@ namespace ICSharpCode.Decompiler.CSharp
AnonymousMethodExpression ame = new AnonymousMethodExpression();
ame.IsAsync = function.IsAsync;
ame.Parameters.AddRange(MakeParameters(function.Parameters, function));
ame.HasParameterList = ame.Parameters.Count > 0;
var builder = new StatementBuilder(
typeSystem,
this.decompilationContext,
@ -2493,7 +2492,6 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2493,7 +2492,6 @@ namespace ICSharpCode.Decompiler.CSharp
if (!isLambda && !parameterReferencingIdentifiers.Any())
{
ame.Parameters.Clear();
ame.HasParameterList = false;
}
Expression replacement;
@ -2530,7 +2528,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2530,7 +2528,7 @@ namespace ICSharpCode.Decompiler.CSharp
var rr = new DecompiledLambdaResolveResult(
function, delegateType, inferredReturnType,
hasParameterList: isLambda || ame.HasParameterList,
hasParameterList: isLambda || ame.Parameters.Any(),
isAnonymousMethod: !isLambda,
isImplicitlyTyped: ame.Parameters.Any(p => p.Type is null));

3
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -561,7 +561,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -561,7 +561,8 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
Space();
}
WriteKeyword(AnonymousMethodExpression.DelegateKeyword);
if (anonymousMethodExpression.HasParameterList)
// No parameters -> "delegate {}" (omit the list); with parameters -> "delegate (...) {}".
if (anonymousMethodExpression.Parameters.Any())
{
Space(policy.SpaceBeforeAnonymousMethodParentheses);
WriteCommaSeparatedListInParenthesis(anonymousMethodExpression.Parameters, policy.SpaceWithinAnonymousMethodParentheses);

8
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/AnonymousMethodExpression.cs

@ -41,14 +41,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -41,14 +41,6 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public bool IsAsync { get; set; }
// used to tell the difference between delegate {} and delegate () {}
bool hasParameterList;
public bool HasParameterList {
get { return hasParameterList || Parameters.Any(); }
set { hasParameterList = value; }
}
[Slot("Roles.Parameter")]
public partial AstNodeCollection<ParameterDeclaration> Parameters { get; }

Loading…
Cancel
Save