You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 30, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: apps/nextra/pages/en/build/smart-contracts/book/functions.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -773,7 +773,7 @@ struct S has key {
773
773
774
774
### Operations on Functions
775
775
776
-
A function value is evaluated by providing the corresponding number of parameters, similar as when calling a named function. During evaluation, the function value is *consumed*. Hence if the value needs to be evaluated multiple times, it's type must have the `copy` ability:
776
+
A function value is evaluated by providing the corresponding number of parameters, similar as when calling a named function. During evaluation, the function value is *consumed*. Hence if the value needs to be evaluated multiple times, its type must have the `copy` ability:
Copy file name to clipboardExpand all lines: apps/nextra/pages/en/build/smart-contracts/linter.mdx
+51Lines changed: 51 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,11 +12,31 @@ If you find any issues, please submit [bugs and feedback](https://github.com/apt
12
12
13
13
14
14
## Lint Checks
15
+
16
+
### `aborting_overflow_checks`
17
+
18
+
Checks for patterns that look like overflow checks done in a C style:
19
+
```move
20
+
// Overflow check
21
+
if (x > x + y) {
22
+
abort 1;
23
+
};
24
+
25
+
// Underflow check
26
+
if (x < x - y) {
27
+
abort 1;
28
+
};
29
+
```
30
+
This pattern in Move does not make sense, as it either aborts immediately or is always true/false.
31
+
15
32
### `almost_swapped`
16
33
Checks for expression patterns that look like a failed swap attempt and notifies the user. These patterns are likely erroneous code. This currently only detects simple access patterns such as assignments to a variable or a field of a struct. Examples include:
17
34
-`a = b; b = a;` which can be correctly swapped with `(a, b) = (b, a);`
18
35
-`a.x = b.x; b.x = a.x;` which can be correctly swapped with `(a.x, b.x) = (b.x, a.x);`
19
36
37
+
### `assert_const`
38
+
Checks for trivial assertions, i.e. `assert!(false)` and `assert!(true)`. The latter is equivalent to a no-op, so can be removed entirely, while the former can be replaced by an abort.
39
+
20
40
### `avoid_copy_on_identity_comparison`
21
41
22
42
Checks for identity comparisons (`==` or `!=`) between copied values of type `vector` or `struct` (i.e., types for which copy can be expensive). It instead suggests to use reference-based identity comparison instead (i.e., use `&x == &y` instead of `x == y`, when the above mentioned conditions meet).
@@ -39,6 +59,16 @@ It is a common Move pattern to provide inline specifications in conditions, espe
39
59
40
60
Note that an `assert!` is translated to a conditional abort, so blocks in `assert!` condition also are reported by this lint.
41
61
62
+
### `known_to_abort`
63
+
64
+
Checks for expressions that will always abort at runtime due to known constant values that violate runtime constraints. This lint helps identify code that will deterministically fail before it reaches production.
65
+
66
+
The following cases are detected:
67
+
68
+
-**Bit shifts with excessive shift amounts**: `x << n` or `x >> n` where `n` is a constant that is greater than or equal to the bit width of `x`'s type. For example, `value << 64` when `value` is of type `u64` will always abort.
69
+
-**Division or modulo by zero**: `x / 0` or `x % 0` operations will always abort at runtime.
70
+
-**Out-of-range type casting**: `constant as type` where the `constant` value is outside the representable range of the target `type`. For example, `300 as u8` will abort since `u8` can only represent values 0-255.
71
+
42
72
### `needless_bool`
43
73
44
74
Checks for patterns of the form (where `x` is any arbitrary boolean expression):
@@ -101,6 +131,27 @@ Checks for patterns where a variable or a field of a struct is assigned to itsel
101
131
-`x = x;`
102
132
-`a.x = a.x;`
103
133
134
+
### `simpler_bool_expression`
135
+
136
+
Checks for boolean patterns that can be simplified through different boolean algebra laws. Examples include:
137
+
- Absorption law:
138
+
-`a && b || a` can be simplified to `a`
139
+
-`a || a && b` can be simplified to `a`
140
+
- Idempotence:
141
+
-`a && a` can be simplified to `a`
142
+
-`a || a` can be simplified to `a`
143
+
- Contradiction
144
+
-`a && !a` can be simplified to `false`
145
+
-`!a && a` can be simplified to `false`
146
+
- Tautology:
147
+
-`a || !a` can be simplified to `true`
148
+
-`!a || a` can be simplified to `true`
149
+
- Distributive law:
150
+
-`(a && b) || (a && c)` can be simplified to `a && (b || c)`
151
+
-`(a || b) && (a || c)` can be simplified to `a || (b && c)`
152
+
153
+
Where `a`, `b` and `c` can either be simple or composed expressions.
154
+
104
155
### `simpler_numeric_expression`
105
156
106
157
Checks for various patterns where a simpler numeric expression can be used instead. In all these cases, the code must already type check, and `x` can be any numeric expression.
0 commit comments