Linting rules
E025: divide-before-multiply
Detects cases where division is evaluated before multiplication.
Metadata
Code:E025Rule:divide-before-multiplyStatus: Preview sincev0.0.1Quick fix: sometimes available
What it does
Detects cases where division is evaluated before multiplication.
Why is this bad?
Division done too early may lose precision (especially for integer arithmetic) and can produce unintended results in subsequent multiplication.
Example
fun main(a: int, b: int, c: int): int {
return a / b * c;}Use instead:
fun main(a: int, b: int, c: int): int {
return a * c / b;
}Behavior notes
The check uses CFG + dataflow:
- reports direct patterns like
(x / y) * zandx * (y / z); - tracks locals tainted by division through assignments and warns when such values are later used in multiplication.
Last updated on