Skip to content

Commit

Permalink
UtilityAnalyzer: Wrong classifications: value in nameof (#7823)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource authored Aug 18, 2023
1 parent dd0da2c commit c1515ba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit c1515ba

Please sign in to comment.