You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicstaticboolMyAwesomeMethod(booldoIt){string?myAwesomeName=null;Parallel.Invoke(()=>{myAwesomeName=doIt?"Banzai!":null;});returnmyAwesomeNameis not null;}
The code given above triggers the following warning: CA1508 'myAwesomeName is not null' is always 'false'. Remove or refactor the condition(s) to avoid dead code.
But ideally speaking, the given code should not trigger CA1508 because at the point we check the value of the object, it can have a non-null value.
Reproduction Steps
Add <AnalysisLevel>9-all</AnalysisLevel> to the csproj file
Compile the code given in the Description section
Expected behavior
CA1508 shouldn't get triggered because at the point we check the value of the object, it can have a non-null value.
Actual behavior
CA1508 is being triggered
Regression?
No response
Known Workarounds
No response
Configuration
.NET 9
Other information
No response
The text was updated successfully, but these errors were encountered:
This isn't specific to Parallel.Invoke; whether Parallel.Invoke will invoke the delegate is part of Invoke's implementation, which the analyzer/compiler isn't privvy to, and thus it doesn't know that Invoke is guaranteed to invoke the delegate... this would be the case for any other such method that accepted a lambda/delegate.
That said, the analyzer really shouldn't be issuing this diagnostic here, simply because it can't know whether the code is dead or not.
Description
The code given above triggers the following warning:
CA1508 'myAwesomeName is not null' is always 'false'. Remove or refactor the condition(s) to avoid dead code.
But ideally speaking, the given code should not trigger
CA1508
because at the point we check the value of the object, it can have a non-null value.Reproduction Steps
<AnalysisLevel>9-all</AnalysisLevel>
to the csproj fileDescription
sectionExpected behavior
CA1508
shouldn't get triggered because at the point we check the value of the object, it can have a non-null value.Actual behavior
CA1508
is being triggeredRegression?
No response
Known Workarounds
No response
Configuration
.NET 9
Other information
No response
The text was updated successfully, but these errors were encountered: