Fix #3894: keep lambda parameter typing consistent#3897
Open
sailro wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.IsImplicitlyTypedconsistent,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:
AnonymousTypesPretty matrix: 24 passedFull 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