Skip to content

Fix RemoveUnusedMembers handling of default parameter reads#80810

Merged
CyrusNajmabadi merged 3 commits intodotnet:mainfrom
molostovvs:molostov/63892/const-field-unused-fix
Nov 29, 2025
Merged

Fix RemoveUnusedMembers handling of default parameter reads#80810
CyrusNajmabadi merged 3 commits intodotnet:mainfrom
molostovvs:molostov/63892/const-field-unused-fix

Conversation

@molostovvs
Copy link
Contributor

fixes #63892

  • treat parameter default value expressions as symbol reads inside lambdas and local funcs
  • add related test cases

fixes #63892

- treat parameter default value expressions as symbol reads inside lambdas and local funcs
- add related test cases
@dotnet-policy-service dotnet-policy-service bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels Oct 18, 2025
private const int _goo = 42;
public void M()
{
var lam = (int x = _goo) => x;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test with delegate (int x = _goo) { }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This results in error CS1065

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DoctorKrolic
Hi! Can you please come back with a review?

@molostovvs
Copy link
Contributor Author

@dotnet-policy-service agree

@molostovvs molostovvs marked this pull request as ready for review October 18, 2025 20:13
@molostovvs molostovvs requested a review from a team as a code owner October 18, 2025 20:14
@molostovvs
Copy link
Contributor Author

@CyrusNajmabadi Hi!
Can you do a pull request review, please?

FixedCode = code,
LanguageVersion = LanguageVersion.CSharp12,
}.RunAsync();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test like so: var lam = (int x = _goo + _bar) => x + y;

also var lam = (int x = MyClass._goo) => x;

thanks!

Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks great! Just a couple of tests to add. If they are added and pass, i'll merge. tnx.

@CyrusNajmabadi CyrusNajmabadi merged commit 350a8fc into dotnet:main Nov 29, 2025
25 of 26 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Nov 29, 2025
@CyrusNajmabadi
Copy link
Contributor

Thanks @molostovvs !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE Usage Analysis Does Not Account for Lambda Default Parameters

4 participants