Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ unsafe void TestMethod()
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that the analyzer will properly handle valid dereference.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
[WorkItem(3538, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3538")]
public async Task TestNotReportedWhenFirstInForeachWithoutBracesAsync()
{
var testCode = @"
public unsafe class TestClass
{
internal void TestMethod(Obj[] objs)
{
foreach (var o in objs)
*o.I = 1;
}

internal struct Obj
{
public int* I;
}
}
";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that the analyzer will properly handle invalid dereference and access of symbols.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ private static void HandleAsteriskToken(SyntaxTreeAnalysisContext context, Synta
context.ReportDiagnostic(Diagnostic.Create(DescriptorNotAtBeginningOfLine, token.GetLocation(), properties));
#pragma warning restore RS1005 // ReportDiagnostic invoked with an unsupported DiagnosticDescriptor
}
else if (allowAtLineStart && firstInLine)
{
// The case below should not trigger
}
else if (!allowPrecedingSpace && precededBySpace)
{
// Dereference symbol '*' should {not be preceded by a space}.
Expand Down