diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Utilities/TokenTypeAnalyzer.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Utilities/TokenTypeAnalyzer.cs index 3e199b79c23..22611734c5d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Utilities/TokenTypeAnalyzer.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Utilities/TokenTypeAnalyzer.cs @@ -137,7 +137,7 @@ name.Parent is MemberAccessExpressionSyntax { } parent when NameIsRightOfIsExpression(name, parent) => ClassifyIdentifierByModel(name), // is i { RawKind: (int)SyntaxKindEx.ConstantPattern } => ClassifyIdentifierByModel(name), // is { X: i } // nameof(i) can be bound to a type or a member - ArgumentSyntax x when IsNameOf(x) => ClassifyIdentifierByModel(name), + ArgumentSyntax x when IsNameOf(x) => IsValueParameterOfSetter(name) ? TokenType.Keyword : ClassifyIdentifierByModel(name), // walk up memberaccess to detect cases like above MemberAccessExpressionSyntax x => ClassifySimpleNameExpressionSpecialContext(x, name), _ => ClassifySimpleNameExpressionSpecialNames(name) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/Utilities/TokenTypeAnalyzerTest.Classifier.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/Utilities/TokenTypeAnalyzerTest.Classifier.cs index 1c0d2124083..64cf5149f91 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/Utilities/TokenTypeAnalyzerTest.Classifier.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/Utilities/TokenTypeAnalyzerTest.Classifier.cs @@ -378,6 +378,8 @@ public class Inner { } [DataRow("_ = [k:value];", true)] [DataRow("_ = this.[u:value];", false)] [DataRow("int [u:Value] = 0; _ = [u:Value]++;", false)] + [DataRow("_ = nameof([k:value]);", true)] + [DataRow("_ = nameof([k:value].ToString);", true)] [DataRow("_ = [k:value].ToString();", true)] [DataRow("_ = [k:value].InnerException.InnerException;", true)] [DataRow("_ = [k:value]?.InnerException.InnerException;", true)]