Open
Description
openedon Nov 20, 2021
Analyzer
Diagnostic ID: RS1034: Prefer 'IsKind' for checking syntax kinds
Analyzer source
NuGet Package: Microsoft.CodeAnalysis.Analyzers
Version: 3.3.3 (Latest)
Describe the bug
The code fix for RS1034 applies a code change that leads to malfunctions at runtime.
Steps To Reproduce
git clone https://github.com/microsoft/vs-threading.git
cd vs-threading
git checkout 07ca567041a077f2814f6b096237a9d76884c5b0
Change FixUtils.cs L104 to:
hasReturnValue = (method.ReturnType as PredefinedTypeSyntax)?.Keyword.Kind() != SyntaxKind.VoidKeyword;
Expected behavior
-hasReturnValue = (method.ReturnType as PredefinedTypeSyntax)?.Keyword.Kind() != SyntaxKind.VoidKeyword;
+hasReturnValue = (method.ReturnType as PredefinedTypeSyntax)?.Keyword.IsKind(SyntaxKind.VoidKeyword) is not true;
(or some other equivalent transaction.
Actual behavior
-hasReturnValue = (method.ReturnType as PredefinedTypeSyntax)?.Keyword.Kind() != SyntaxKind.VoidKeyword;
+hasReturnValue = !(method.ReturnType as PredefinedTypeSyntax).IsKind(SyntaxKind.VoidKeyword);
The transaction here is not equivalent in behavior. Note the drop of the .Keyword
in the expression, which leads to the IsKind
to always return false
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment