[analyzer] suggest truncate-divide when double-from-divide is used #50942
Labels
analyzer-ux
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
P3
A lower priority bug or feature request
type-enhancement
A request for a change that isn't a bug
Forked from dart-lang/linter#3930 (comment)
@rakudrama suggests a new error message for code like this:
Currently this code produces an error,
argument_type_not_assignable
: "The argument type 'double' can't be assigned to the parameter type 'int'." But it could suggest using/~
instead of/
. Then users would be less likely to write(s.length / 2).toInt()
, and we could retire thedivision_optimization
hint (which fires for code like(s.length / 2).toInt()
.However, to make a sufficiently complete replacement, we'd have to catch more than
argument_type_not_assignable
. I can think of the following other cases:I'm sure there are more.
Also, is it sufficient to catch
x / y
asint
? Or would we want to go deeper and catch, for example,(x / y) + 1
?CC @rakudrama @bwilkerson
The text was updated successfully, but these errors were encountered: