Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/RCS1031, RCS1208 and RCS1061 #1062

Merged
merged 17 commits into from
Apr 21, 2023

Conversation

jamesHargreaves12
Copy link
Contributor

This PR extends the local variable check from #1039 to RCS1061 and also checks variables assigned during pattern matching in the case of RCS1031.

Slightly embarrassingly, I didn't check all the ReduceIfNestingAnalysis code paths in #1039 and so I didn't realise that the AnalyzeDataFlow can only handle an argument of type ExpressionSyntax or StatementSyntax. If you pass anything else, it will throw a run time error. This PR solves this issue through the new helper function IfStatementLocalVariableAnalysis.TryGetOuterScope which handles the intricacies of this. I have also added a number of new tests at the level of RCS1208 to enforce this behaviour.

It is currently not trivial to test the Loop / Switch sections of ReduceIfNestingAnalysis.AnalyzeCore via the analyzer as it passes through ReduceIfNestingOptions.None. However, I manually removed the guard clause on lines 63 and 90 and confirmed that it was working correctly.

@josefpihrt
Copy link
Collaborator

josefpihrt commented Apr 15, 2023

@jamesHargreaves12 I noticed that there multiple small fixes like formatting, trailing whitespace, implicit/explicit type etc. I suggest to run script tools/cli_fix.ps1 to fix those (and dotnet format).

@josefpihrt
Copy link
Collaborator

@jamesHargreaves12 I would like to release new version in about one week and I would like to include this PR in the new version. Could you let me know if you will have time to address my comments so the PR can me merged? Thanks.

@josefpihrt josefpihrt force-pushed the fix/RCS1031-and-RCS1208 branch from 610dc14 to 94323c7 Compare April 21, 2023 11:45
@josefpihrt josefpihrt merged commit 3b534ee into dotnet:main Apr 21, 2023
Haarmees pushed a commit to Haarmees/Roslynator that referenced this pull request Oct 30, 2023
Co-authored-by: Josef Pihrt <josef@pihrt.net>
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.

2 participants