Open eduherminio opened 3 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
I wonder if this can be turned into a generalized heuristic. Some possible examples:
If the parameter is named capacity, count, or similar; and if the input to the parameter is a char which has been auto-widened to an int; trigger the analyzer.
If there are two method overloads MyMethod(..., string, ...)
and MyMethod(..., int, ...)
(but no MyMethod(..., char, ...)
), and if the call site matched the second overload because a char was auto-widened to an int, trigger the analyzer.
Context:
Adding a
StringBuilder(char)
constructor was originally proposed in #20848 due to the existingStringBuilder(int capacity)
constructor accepting achar
as an argument (i.e.:StringBuilder('a')
), but the proposal was finally rejected.Since this scenario will generally denote a bug, the possibility of creating an analyzer for it was brought up during the review of the proposal, but apparently was discarded or never formalized.
After opening a GH discussion about it, I was suggested in to formally propose the creation of such analyzer (https://github.com/dotnet/runtime/discussions/46052#discussioncomment-210538).