Open jcouv opened 5 years ago
If only we had a framework for doing static analysis to avoid mistakes like this 😉
Indeed. I'm planning to create analyzer/fixer for this. The trouble is that when you switch to .Equals
, we should make the comparison option explicit, so that is still a human decision.
Note: having these comparison options be available at the ISymbol layer would be very helpful. IDE needs to make these sorts of decisions as well. And we've gone about it by trying to reeimplement the compiler rules.
Could we use some Obsolete tricks to forbid those?
@alrz Yes, that could help, but the main issue is dealing with existing usages (there's many).
As pointed out by https://github.com/dotnet/roslyn/issues/31740, some binding code uses strict type comparison, but should be using nullable-insensitive comparison.
Update: I've converted usages of
==
and!=
to explicit comparison withConsiderEverything2
. I've yet to track down other implicit comparisons (such asDictionary<TypeSymbol, ...>
orHashSet<TypeSymbol>
).