Description
I'm not sure if this is by intent but I think there is an issue with recognizing S1125 Boolean literals should not be redundant when source type is not bool.
Repro steps
var exception = new Exception();
exception.Data.Add("handled", true);
if (exception.Data.Contains("handled") && exception.Data["handled"] is true)
{
// do something
}
Data is of type IDictionary - which has kay/value as object. Therefore I think is true pattern matching is valid at this point. If I am wrong please correct me :)
Removing the pattern matching results in code that can not be compiled
Expected behavior
My expectation would be, that that pattern matching is valid.
Actual behavior
Actual behavior is a warning - which leads to build error when having warnings as errors enabled.
Known workarounds
Using as operator for converting doesn't give a warning:
var exception = new Exception();
exception.Data.Add("handled", true);
if (exception.Data.Contains("handled") && (exception.Data["handled"] as bool?) == true)
{
// do something
}
Related information
- C#/VB.NET Plugins version: 9.7.0.75501
- Visual Studio version <-- None ... using Rider 2023.2
- MSBuild / dotnet version: 7.0.400
- SonarScanner for .NET version (if used)
- Operating System: OSX Ventura 13.5
Description
I'm not sure if this is by intent but I think there is an issue with recognizing S1125
Boolean literals should not be redundantwhen source type is not bool.Repro steps
Datais of type IDictionary - which has kay/value as object. Therefore I thinkis truepattern matching is valid at this point. If I am wrong please correct me :)Removing the pattern matching results in code that can not be compiled
Expected behavior
My expectation would be, that that pattern matching is valid.
Actual behavior
Actual behavior is a warning - which leads to build error when having warnings as errors enabled.
Known workarounds
Using
asoperator for converting doesn't give a warning:Related information