Skip to content

Commit

Permalink
UtilityAnalyzer: Wrong classifications: ref types (#7824)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource authored Aug 18, 2023
1 parent 18f120f commit 360a2a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ private static bool IsInTypeContext(SimpleNameSyntax name) =>
{ RawKind: (int)SyntaxKind.ParenthesizedLambdaExpression } x => ((ParenthesizedLambdaExpressionSyntaxWrapper)x).ReturnType == name,
{ RawKind: (int)SyntaxKindEx.FileScopedNamespaceDeclaration } x => ((FileScopedNamespaceDeclarationSyntaxWrapper)x).Name == name,
{ RawKind: (int)SyntaxKindEx.TupleElement } x => ((TupleElementSyntaxWrapper)x).Type == name,
{ RawKind: (int)SyntaxKindEx.RefType } x => ((RefTypeSyntaxWrapper)x).Type == name,
_ => false,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,27 @@ public void M()
}
""", allowSemanticModel, ignoreCompilationErrors);
[DataTestMethod]
[DataRow("[t:Int32]", false)]
[DataRow("[t:Int32]?", false)]
[DataRow("System.[t:Int32]", false)]
[DataRow("System.Nullable<[t:Int32]>", false)]
[DataRow("[t:T]", false)]
public void IdentifierToken_Type_Ref(string refTypeName, bool allowSemanticModel = true) =>
ClassifierTestHarness.AssertTokenTypes($$"""
using System;
public class Test<T>
{
{{refTypeName}} item;
public ref {{refTypeName}} M()
{
return ref item;
}
}
""", allowSemanticModel);
#endif
[DataTestMethod]
Expand Down

0 comments on commit 360a2a5

Please sign in to comment.