Skip to content

Fix RCS1118 to not report local variable passed as 'in' argument - #1782

Merged
josefpihrt merged 3 commits into
dotnet:mainfrom
NoahStolk:fix-rcs1118-in-argument
Aug 1, 2026
Merged

Fix RCS1118 to not report local variable passed as 'in' argument#1782
josefpihrt merged 3 commits into
dotnet:mainfrom
NoahStolk:fix-rcs1118-in-argument

Conversation

@NoahStolk

Copy link
Copy Markdown
Contributor

Fixes #1781

RCS1118 reports a local variable that is later passed to a parameter with an explicit in argument keyword. Marking such a local as const produces code that does not compile, because a constant cannot be passed by readonly reference.

Added two new tests: one for an in parameter and one for a ref readonly parameter. Both fail on main and pass with the fix.

@josefpihrt josefpihrt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please update change log.

Comment thread src/Tests/Analyzers.Tests/RCS1118MarkLocalVariableAsConstTests.cs
@NoahStolk
NoahStolk requested a review from josefpihrt August 1, 2026 19:16
@josefpihrt
josefpihrt merged commit b646f54 into dotnet:main Aug 1, 2026
17 checks passed
@josefpihrt

Copy link
Copy Markdown
Collaborator

@NoahStolk Thank you for your contribution!

@NoahStolk
NoahStolk deleted the fix-rcs1118-in-argument branch August 1, 2026 20:11
This was referenced Aug 8, 2026
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.

RCS1118 suggests const for a local variable that is passed as an in argument

2 participants