Registry Mirror
Skip to content

Conversation

@sailro

@sailro sailro commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3894.

Problem

When a lambda parameter has an anonymous type, ILSpy omits that unnameable type but leaves
sibling parameter types explicit. The resulting mixed form, such as
(item, int context) => ..., is rejected with CS0748.

Any source lambda with an anonymous-typed parameter must have used implicit typing for its
whole parameter list, because the anonymous type cannot be written explicitly.

Solution

Build the parameter list first, detect whether any parameter contains an anonymous type, and
then remove every parameter type when the remaining parameter syntax permits implicit typing.

This keeps the emitted syntax and DecompiledLambdaResolveResult.IsImplicitlyTyped consistent,
while leaving unrepresentable modifier/attribute combinations as a conservative fallback.

Tests

Added a Roslyn Pretty regression using a generic delegate whose first parameter becomes an
anonymous type and whose second parameter is int.

Validation:

  • Release solution build: 0 warnings, 0 errors

  • Full solution test suite

  • At least one test covering the code changed

@sailro
sailro force-pushed the fix-3894-mixed-lambda branch from 51e4b95 to 2b9158d Compare August 1, 2026 08:39
@siegfriedpammer siegfriedpammer added this to the ILSpy Dev Meeting 2026 milestone Aug 3, 2026
@sailro
sailro marked this pull request as draft August 8, 2026 09:14
@dgrunwald
dgrunwald marked this pull request as ready for review August 16, 2026 06:37
sailro and others added 2 commits August 16, 2026 08:38
An anonymous parameter type cannot be named, so the original lambda must
have used implicit parameters throughout. Emit the whole parameter list
implicitly instead of mixing implicit and explicit declarations.

Assisted-by: Copilot:gpt-5.6-sol:GitHub Copilot CLI
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 86d2918e-5a24-48b4-9a86-41d331ec3720
@dgrunwald
dgrunwald force-pushed the fix-3894-mixed-lambda branch from 2b9158d to e7bed9c Compare August 16, 2026 06:38
@dgrunwald
dgrunwald merged commit 40e6f2c into icsharpcode:master Aug 16, 2026
9 checks passed
@sailro
sailro deleted the fix-3894-mixed-lambda branch August 16, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lambda with an anonymous parameter type gets mixed parameter typing (CS0748)

3 participants