Conversation
christophwille
left a comment
There was a problem hiding this comment.
Automated high-effort review (Claude Code, multi-agent find + adversarial-verify) of head 0116f24.
The direction looks good, and the head commit ("Keep 'delegate {}' when a parameter type is inaccessible") already resolves one issue the review had flagged against the earlier state: lambda expansion forcing unnameable delegate parameter types into an emitted parameter list. Six findings remain, posted inline:
- Correctness (confirmed):
DeclareVariables.ResolveCollisionscan emit invalid C# likex => int num = x;when the expression-lambda body preserved by the new stop condition is itself the matching assignment. Pre-existing on master, but this PR touches exactly that stop condition. - Output regression (confirmed): unused-parameter anonymous methods no longer collapse to
delegate {}when the parameter types are accessible, so synthetic-but-valid parameter names (ilasmA_0/A_1, obfuscators) now leak into output - visible in this PR's own Issue1038 expectation change. - Comment accuracy:
ref/out/inare expressible in explicitly-typed lambda parameter lists; the comment's "shapes a lambda cannot express" rationale is wrong for those modifiers. - Test coverage: the new invalid-name (
<p0>) branch inAssignVariableNamesis exercised by no fixture after the Bug971 rewrite (the newInaccessibleParameterTypes.iluses empty parameter names, which take thevariables[i].Namefallback instead). - Test coverage: the retained delegate-syntax fallback for
ref/out/in/paramsparameters has no fixture. - Simplification:
HasGeneratedName = truein the invalid-name branch is redundant; thecontinueis the load-bearing part.
87e477f to
af37a1d
Compare
|
All six findings are addressed in the force-pushed branch (rebased on master, fixes squashed into the commits they belong to). Full decompiler suite green locally (3371 tests) and CI is green on all platforms. 1. 2. Synthetic parameter names leaking — One honest limitation: 3. Comment accuracy — rewritten. It no longer claims 4. 5. ref/out/in/params fallback untested — new Pretty fixture 6. Redundant Worth recording from the CI round-trip: restoring Posted by an AI agent (Claude) on Siegfried's behalf. |
Under UseLambdaSyntax, anonymous functions became lambdas only when an
expression body was possible; statement-bodied ones kept C# 2 delegate
syntax. Now every anonymous function whose parameter shape a lambda can
express uses lambda syntax; delegate syntax remains for ref/out/in and
params parameters and for pre-C# 3 language profiles.
Two latent issues surfaced by the wider lambda coverage: DeclareVariables
assumed an insertion point directly under a LambdaExpression is an
expression body it must convert to a block, which block-bodied lambdas
now violate; and anonymous methods declared without a parameter list
carry compiler-generated parameter names like '<p0>' that are not valid
identifiers, so the lambda's mandatory parameter list regenerates such
names from the parameter type: (object obj, EventArgs e) => ...
A side effect visible in fixtures: an explicit parameter list can make
a delegate-creation cast redundant that bare 'delegate' syntax needed
for overload resolution, e.g. new Thread((ThreadStart)delegate { })
becomes new Thread(() => { }).
Assisted-by: Claude:claude-fable-5:Claude Code
The parameter-list-less anonymous method form is compatible with any delegate signature, and C# code must rely on exactly that when a delegate's parameter types cannot be named at the use site: IL, unlike C#, permits a delegate signature to reference less accessible types. Expanding such an anonymous method into a lambda would force the unnameable type into a parameter list. Keep the delegate form, with its parameter list dropped, when the parameters are unused and one of their types is not accessible from the current context. Assisted-by: Claude:claude-fable-5:Claude Code
af37a1d to
a22b545
Compare
With
UseLambdaSyntaxenabled, anonymous functions were emitted as lambdas only when an expression body was possible; every statement-bodied anonymous function still decompiled to C# 2delegatesyntax. This PR extends the setting to emit statement lambdas: any anonymous function whose parameter shape a lambda can express now uses lambda syntax.delegatesyntax remains forref/out/inandparamsparameters, and for pre-C# 3 language profiles (SetLanguageVersionstill disables the setting there).Two latent issues surfaced by the wider lambda coverage and are fixed here:
DeclareVariables.ResolveCollisionsstopped its insertion-point walk at any node whose parent is aLambdaExpression, assuming an expression body that declaration insertion then converts to a block. A statement-bodied lambda's own block now reaches that path and tripped aDebug.Assert; the stop now applies only to actual expression bodies.<p0>,<sender>) that are not valid C# identifiers. The old output hid them by omitting the parameter list; a lambda cannot, soAssignVariableNamesnow treats an invalid metadata name like a missing one and regenerates it from the parameter type:(object obj, EventArgs e) => {...}.A visible side effect captured in the fixtures: an explicit parameter list can make a delegate-creation cast redundant that bare
delegateneeded for overload resolution -new Thread((ThreadStart)delegate { })becomesnew Thread(() => { }).Verification: full decompiler suite green (3317 passed). Differential check with decompdiff (master vs. this branch, fresh Release builds) over 12 real-world assemblies / 2341 types - Newtonsoft.Json 9, EntityFramework 6.2, Autofac, Castle.Core, Moq, NLog, log4net, Dapper, RestSharp, SharpZipLib, Mono.Cecil, NUnit 3.5: 68 types changed, every changed line is the delegate-to-lambda rewrite (parameter names from metadata are preserved), 0 new errors, and no deltas in lines, gotos,
//IL_warnings, or compiler-generated name leaks.This PR description was written by the Claude Code agent session that authored the change.
🤖 Generated with Claude Code