There are several types of functions and various reasons why some "swappable parameters" cannot be fixed with changing the parameters' types, etc. The most common example might be int min(int a, int b)... no matter what you do, the two parameters must remain the same type.
The filtering heuristic implemented in this patch deals with trying to find such functions during the modelling and building of the swappable parameter range. If the parameter currently scrutinised matches either of the predicates below, it will be regarded as not swappable even if the type of the parameter matches.
On average, 50% of the results are silenced by this heuristic (over a set of test projects we investigated). This heuristic has the possibility of producing false negatives, and no path-sensitive analysis is made, as usual in Tidy. However, the reduction of the findings greatly allows developers to see the more useful results about the dodgiest interfaces first and not be deafened by the noise.
The modelling "similarly used parameters" is toggleable by the user as a checker option. Due to the massive benefits this option brings for users who run this check for the first time on their project, the default is to have this turned on.
- Common expression: if both parameters are found in a common expression somewhere in the function, they are silenced. This heuristic is an absolute blast because it deals with arithmetics, comparisons, forwarding function calls, etc. out of the box at the same time.
- Returns: if both parameters are returned from different statements of the function, they are silenced. This deals with "switch-like" functions.
- Pass to same function: if both parameters are passed to the same function('s overload) to the same index, they are silenced. This deals with "dispatch-like" functions.
- Same member access: if the same member field is accessed or method is called on the two parameters, even if distinct expressions, they are "used in a similar fashion" and are silenced.