-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
408 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
external-crates/move/crates/move-compiler/tests/linter/false_negative_equal_operand.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
warning[Lint W01003]: math operator can be simplified | ||
┌─ tests/linter/false_negative_equal_operand.move:5:18 | ||
│ | ||
5 │ let _ = (x + 0) == x; // Semantically same operands but syntactically different | ||
│ ^^^^^ | ||
│ │ │ | ||
│ │ Because of this operand | ||
│ This operation has no effect and can be removed | ||
│ | ||
= This warning can be suppressed with '#[allow(lint(unnecessary_math))]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
warning[Lint W01003]: math operator can be simplified | ||
┌─ tests/linter/false_negative_equal_operand.move:6:18 | ||
│ | ||
6 │ let _ = (x * 1) == x; // Semantically same operands but syntactically different | ||
│ ^^^^^ | ||
│ │ │ | ||
│ │ Because of this operand | ||
│ This operation has no effect and can be removed | ||
│ | ||
= This warning can be suppressed with '#[allow(lint(unnecessary_math))]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
warning[Lint W02011]: Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
┌─ tests/linter/false_negative_equal_operand.move:9:17 | ||
│ | ||
9 │ let _ = get_constant() == get_constant(); // Same value but lint won't catch it | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
│ | ||
= This warning can be suppressed with '#[allow(lint(equal_operands))]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
warning[Lint W02011]: Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
┌─ tests/linter/false_negative_equal_operand.move:19:17 | ||
│ | ||
19 │ let _ = s == s; // Should trigger lint | ||
│ ^^^^^^ Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
│ | ||
= This warning can be suppressed with '#[allow(lint(equal_operands))]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
24 changes: 24 additions & 0 deletions
24
external-crates/move/crates/move-compiler/tests/linter/false_negative_equal_operand.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module 0x42::false_negative_equal_operand { | ||
fun test_false_negatives() { | ||
// Complex expressions that are effectively the same but syntactically different | ||
let x = 10; | ||
let _ = (x + 0) == x; // Semantically same operands but syntactically different | ||
let _ = (x * 1) == x; // Semantically same operands but syntactically different | ||
|
||
// Function calls that return the same value | ||
let _ = get_constant() == get_constant(); // Same value but lint won't catch it | ||
} | ||
|
||
fun get_constant(): u64 { 42 } | ||
|
||
// Additional test for struct equality | ||
struct TestStruct has copy, drop { value: u64 } | ||
|
||
fun test_struct_operations() { | ||
let s = TestStruct { value: 10 }; | ||
let _ = s == s; // Should trigger lint | ||
|
||
let s2 = TestStruct { value: 10 }; | ||
let _ = s == s2; // Should not trigger lint (different instances) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ates/move/crates/move-compiler/tests/linter/false_negative_meaningless_math_operation.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
warning[Lint W02011]: Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
┌─ tests/linter/false_negative_meaningless_math_operation.move:3:14 | ||
│ | ||
3 │ x * (y - y) // This is effectively * 0, but is not currently caught | ||
│ ^^^^^ Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
│ | ||
= This warning can be suppressed with '#[allow(lint(equal_operands))]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
8 changes: 8 additions & 0 deletions
8
...l-crates/move/crates/move-compiler/tests/linter/false_negative_unnecessary_while_loop.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
warning[Lint W02011]: Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
┌─ tests/linter/false_negative_unnecessary_while_loop.move:7:16 | ||
│ | ||
7 │ while (true && true) {}; | ||
│ ^^^^^^^^^^^^ Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
│ | ||
= This warning can be suppressed with '#[allow(lint(equal_operands))]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
78 changes: 78 additions & 0 deletions
78
external-crates/move/crates/move-compiler/tests/linter/false_positive_equal_operand.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
warning[W09002]: unused variable | ||
┌─ tests/linter/false_positive_equal_operand.move:4:13 | ||
│ | ||
4 │ let mut_ref = &mut 0; | ||
│ ^^^^^^^ Unused local variable 'mut_ref'. Consider removing or prefixing with an underscore: '_mut_ref' | ||
│ | ||
= This warning can be suppressed with '#[allow(unused_variable)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
error[E01002]: unexpected token | ||
┌─ tests/linter/false_positive_equal_operand.move:5:15 | ||
│ | ||
5 │ while *mut_ref != *mut_ref { // Legitimate use: checking for changes in mutable reference | ||
│ ^ | ||
│ │ | ||
│ Unexpected '*' | ||
│ Expected '(' | ||
|
||
warning[W09002]: unused variable | ||
┌─ tests/linter/false_positive_equal_operand.move:10:13 | ||
│ | ||
10 │ let nan_check = is_nan(1.0); // Simulated floating point check | ||
│ ^^^^^^^^^ Unused local variable 'nan_check'. Consider removing or prefixing with an underscore: '_nan_check' | ||
│ | ||
= This warning can be suppressed with '#[allow(unused_variable)]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
error[E01002]: unexpected token | ||
┌─ tests/linter/false_positive_equal_operand.move:10:34 | ||
│ | ||
10 │ let nan_check = is_nan(1.0); // Simulated floating point check | ||
│ ^ | ||
│ │ | ||
│ Unexpected '0' | ||
│ Expected an identifier or a decimal number | ||
|
||
error[E13001]: feature is not supported in specified edition | ||
┌─ tests/linter/false_positive_equal_operand.move:10:34 | ||
│ | ||
10 │ let nan_check = is_nan(1.0); // Simulated floating point check | ||
│ ^ Positional fields are not supported by current edition 'legacy', only '2024.alpha' and '2024.beta' support this feature | ||
│ | ||
= You can update the edition in the 'Move.toml', or via command line flag if invoking the compiler directly. | ||
|
||
warning[Lint W02011]: Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
┌─ tests/linter/false_positive_equal_operand.move:19:17 | ||
│ | ||
19 │ assert!(x <= x && x <= y, 0); // Legitimate use in monotonicity checks | ||
│ ^^^^^^ Equal operands detected in binary operation, which might indicate a logical error or redundancy. | ||
│ | ||
= This warning can be suppressed with '#[allow(lint(equal_operands))]' applied to the 'module' or module member ('const', 'fun', or 'struct') | ||
|
||
error[E04007]: incompatible types | ||
┌─ tests/linter/false_positive_equal_operand.move:33:9 | ||
│ | ||
31 │ fun reference_equals<T>(a: &T, b: &T): bool { | ||
│ -- Given: '&T' | ||
32 │ // Simulated reference equality check | ||
33 │ std::hash::sha2_256(a) == std::hash::sha2_256(b) | ||
│ ^^^^^^^^^^^^^^^^^^^^^^ Invalid call of 'std::hash::sha2_256'. Invalid argument for parameter 'data' | ||
│ | ||
┌─ /Users/dmr/Projects/rust/sui-network/external-crates/move/crates/move-stdlib/sources/hash.move:9:38 | ||
│ | ||
9 │ native public fun sha2_256(data: vector<u8>): vector<u8>; | ||
│ ---------- Expected: 'vector<u8>' | ||
|
||
error[E04007]: incompatible types | ||
┌─ tests/linter/false_positive_equal_operand.move:33:35 | ||
│ | ||
31 │ fun reference_equals<T>(a: &T, b: &T): bool { | ||
│ -- Given: '&T' | ||
32 │ // Simulated reference equality check | ||
33 │ std::hash::sha2_256(a) == std::hash::sha2_256(b) | ||
│ ^^^^^^^^^^^^^^^^^^^^^^ Invalid call of 'std::hash::sha2_256'. Invalid argument for parameter 'data' | ||
│ | ||
┌─ /Users/dmr/Projects/rust/sui-network/external-crates/move/crates/move-stdlib/sources/hash.move:9:38 | ||
│ | ||
9 │ native public fun sha2_256(data: vector<u8>): vector<u8>; | ||
│ ---------- Expected: 'vector<u8>' | ||
|
35 changes: 35 additions & 0 deletions
35
external-crates/move/crates/move-compiler/tests/linter/false_positive_equal_operand.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module 0x42::false_positive_equal_operand { | ||
fun test_false_positives() { | ||
// Iterator-like patterns where comparing same variable is intentional | ||
let mut_ref = &mut 0; | ||
while *mut_ref != *mut_ref { // Legitimate use: checking for changes in mutable reference | ||
break | ||
}; | ||
|
||
// Checking for NaN (Not a Number) in floating point implementations | ||
let nan_check = is_nan(1.0); // Simulated floating point check | ||
|
||
// Checking for pointer/reference equality (if Move had raw pointers) | ||
let obj = object(); | ||
let _ = reference_equals(obj, obj); // Legitimate use: checking if references point to same object | ||
|
||
// Checking for monotonicity | ||
let x = 10; | ||
let y = 20; | ||
assert!(x <= x && x <= y, 0); // Legitimate use in monotonicity checks | ||
} | ||
|
||
// Helper functions for false positive cases | ||
fun is_nan(_x: u64): bool { | ||
false // Simulated NaN check | ||
} | ||
|
||
fun object(): &vector<u8> { | ||
&vector[1, 2, 3] | ||
} | ||
|
||
fun reference_equals<T>(a: &T, b: &T): bool { | ||
// Simulated reference equality check | ||
std::hash::sha2_256(a) == std::hash::sha2_256(b) | ||
} | ||
} |
Oops, something went wrong.