-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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
- Original PR: Fix method check for callback and returns #429
- Comment: Fix method check for callback and returns #429 (comment)
- Reported by: @rjmurillo