Skip to content

Potential false positive matches with StartsWith check in callback/returns symbol detection #461

@coderabbitai

Description

@coderabbitai

Description

A potential bug was identified in the callback/returns symbol detection logic that could cause false positive matches.

Problem

In tests/Moq.Analyzers.Benchmarks/CallbackReturnsSymbolBenchmarks.cs (lines 118-119), the current implementation uses StartsWith to check containing type names:

bool isCallback = string.Equals(symbol.Name, "Callback", StringComparison.Ordinal)
    && containingTypeName.StartsWith("Moq.Language.ICallback", StringComparison.Ordinal);

This approach could incorrectly match unintended types. For example, a type named "Moq.Language.ICallbackExtended" would incorrectly match the callback check, leading to false positives.

Impact

This could cause the symbol detection logic to incorrectly identify methods as callback or return symbols when they shouldn't be, potentially affecting analyzer behavior.

Suggested Solution

Replace the StartsWith check with exact string comparison to ensure only the intended types "Moq.Language.ICallback" and "Moq.Language.IReturns" match.

References

Metadata

Metadata

Assignees

Labels

.NETPull requests that update .net codetriage

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions