You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positive - C# IEquatable: Equals(object) not implemented alert when Equals(object?) is implemented #21128
CodeQL will complain about a missing override for Equals(object obj) not existing, if the Equals method is implemented within a nullable object as parameter. Using Equals(object? obj) is valid.
Two different alerts appeared on a PR.
Code sample
Sadly, working in closed source, but this sample should do. I do not know if this triggers the false positive in practice, as I can't push it to test, but it should give you a good example. I also added a small a bit of code to show that Equals(object? obj) is valid and working when using Equals().
The CodeQl error message goes as follows for the override bool Equals(object? obj) line: Class 'MyClass' does not implement Equals(object), but it implements IEquatable.Equals
The IEquatable.Equals points to bool Equals(MyClass? other).
Error 2 (alert):
The warning goes for the same function override bool Equals(object? obj) The declaring(MyClass) type of this 'Equals(Object)' method does not override 'Equals(object)'.
Activity
hvitved commentedon Feb 16, 2026
I believe the fix here may be to remove all theresult.getParameter(0).getType() instanceof ObjectTypeoccurrences from https://github.com/github/codeql/blob/28b6aa8616a393ebb45186e3ba4df004a0f3ef4e/csharp/ql/lib/semmle/code/csharp/frameworks/System.qll.hvitved commentedon Feb 18, 2026
I have not been able to reproduce the false positives (see #21342).