Skip to content

Fix #3894: keep lambda parameter typing consistent#3897

Open
sailro wants to merge 1 commit into
icsharpcode:masterfrom
sailro:fix-3894-mixed-lambda
Open

Fix #3894: keep lambda parameter typing consistent#3897
sailro wants to merge 1 commit into
icsharpcode:masterfrom
sailro:fix-3894-mixed-lambda

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:

  • AnonymousTypes Pretty matrix: 24 passed

  • Full Pretty suite: 1,906 passed, 5 existing skips

  • Release solution build: 0 warnings, 0 errors

  • Full solution test suite: 4,885 passed, 15 existing skips

  • At least one test covering the code changed

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
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)

1 participant