diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-commands/mixed_lvalue.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-commands/mixed_lvalue.exp new file mode 100644 index 00000000000000..f13c591a2243b7 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-commands/mixed_lvalue.exp @@ -0,0 +1,13 @@ + +Diagnostics: +error: invalid assignment + ┌─ tests/unused-assignment/v1-commands/mixed_lvalue.move:14:19 + │ +14 │ (_, _, _, s.f) = four(); + │ ^^^ Invalid assignment syntax. Expected: a local, a field write, or a deconstructing assignment + +error: invalid assignment + ┌─ tests/unused-assignment/v1-commands/mixed_lvalue.move:15:19 + │ +15 │ (_, _, _, *r_ref) = four(); + │ ^^^^^^ Invalid assignment syntax. Expected: a local, a field write, or a deconstructing assignment diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-commands/mixed_lvalue.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-commands/mixed_lvalue.move new file mode 100644 index 00000000000000..2858e5b6d2a343 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-commands/mixed_lvalue.move @@ -0,0 +1,17 @@ +module 0x8675309::A { + + struct S has drop { f: u64 } + + fun four(): (u64, u64, u64, u64) { + (0, 1, 2, 3) + } + + public fun mixed() { + let r = 0; + let r_ref = &mut r; + let s = S { f: 0 }; + + (_, _, _, s.f) = four(); + (_, _, _, *r_ref) = four(); + } +} diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_partial_resource.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_partial_resource.exp new file mode 100644 index 00000000000000..7a85759453cee6 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_partial_resource.exp @@ -0,0 +1,25 @@ + +Diagnostics: +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/assign_partial_resource.move:6:21 + │ +6 │ if (cond) { r = R{}; }; + │ ^^^^^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/assign_partial_resource.move:13:29 + │ +13 │ if (cond) {} else { r = R{}; }; + │ ^^^^^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/assign_partial_resource.move:20:24 + │ +20 │ while (cond) { r = R{} }; + │ ^^^^^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/assign_partial_resource.move:27:16 + │ +27 │ loop { r = R{} } + │ ^^^^^^^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_partial_resource.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_partial_resource.move new file mode 100644 index 00000000000000..6b77947727f1e6 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_partial_resource.move @@ -0,0 +1,34 @@ +module 0x8675309::M { + struct R {} + + fun t1(cond: bool) { + let r: R; + if (cond) { r = R{}; }; + r = R{}; + R{} = r; + } + + fun t2(cond: bool) { + let r: R; + if (cond) {} else { r = R{}; }; + r = R{}; + R{} = r; + } + + fun t3(cond: bool) { + let r: R; + while (cond) { r = R{} }; + r = R{}; + R{} = r; + } + + fun t4() { + let r: R; + loop { r = R{} } + } + + fun t5(cond: bool, x: T, y: T): (T, T) { + if (cond) { x = y }; + (x, y) + } +} diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_resource.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_resource.exp new file mode 100644 index 00000000000000..a0ba8ccfbfe60b --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_resource.exp @@ -0,0 +1,13 @@ + +Diagnostics: +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/assign_resource.move:5:17 + │ +5 │ let r = R{}; + │ ^^^ + +warning: Unused assignment to `r`. Consider removing or prefixing with an underscore: `_r` + ┌─ tests/unused-assignment/v1-locals/assign_resource.move:29:17 + │ +29 │ let r = R{}; + │ ^^^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_resource.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_resource.move new file mode 100644 index 00000000000000..cd6ace6d633601 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/assign_resource.move @@ -0,0 +1,37 @@ +module 0x8675309::M { + struct R {} + + fun t0() { + let r = R{}; + r = R{}; + R{} = r; + } + + fun t1(cond: bool) { + let r = R{}; + if (cond) { r = R{}; }; + R{} = r; + } + + fun t2(cond: bool) { + let r = R{}; + if (cond) {} else { r = R{}; }; + R{} = r; + } + + fun t3(cond: bool) { + let r = R{}; + while (cond) { r = R{} }; + R{} = r; + } + + fun t4() { + let r = R{}; + loop { r = R{}; R {} = r } + } + + fun t5(x: T, y: T): T { + x = y; + x + } +} diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/struct_use_before_assign.exp b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/struct_use_before_assign.exp new file mode 100644 index 00000000000000..e8dbffafd0ea6d --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/struct_use_before_assign.exp @@ -0,0 +1,131 @@ + +Diagnostics: +warning: Unused local variable `z`. Consider removing or prefixing with an underscore: `_z` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:8:13 + │ +8 │ let z = y; + │ ^ + +warning: Unused local variable `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:9:13 + │ +9 │ let q = x; + │ ^ + +warning: Unused local variable `z`. Consider removing or prefixing with an underscore: `_z` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:17:13 + │ +17 │ let z = y; + │ ^ + +warning: Unused local variable `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:18:13 + │ +18 │ let q = x; + │ ^ + +warning: Unused local variable `z`. Consider removing or prefixing with an underscore: `_z` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:24:13 + │ +24 │ let z = y; + │ ^ + +warning: Unused local variable `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:25:13 + │ +25 │ let q = x; + │ ^ + +warning: Unused local variable `z`. Consider removing or prefixing with an underscore: `_z` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:30:13 + │ +30 │ let z = y; + │ ^ + +warning: Unused local variable `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:31:13 + │ +31 │ let q = x; + │ ^ + + +Diagnostics: +error: use of unassigned local `g` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:6:17 + │ +6 │ let r = R { f: 3, g }; + │ ^^^^^^^^^^^^^ + +error: use of unassigned local `y0` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:15:17 + │ +15 │ let r = R { f: x0, g: y0 }; + │ ^^^^^^^^^^^^^^^^^^ + +error: use of unassigned local `r` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:23:13 + │ +23 │ let R { f: x, g: y } = r; + │ ^^^^^^^^^^^^^^^^ + +error: use of unassigned local `y` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:30:17 + │ +30 │ let z = y; + │ ^ + +error: use of unassigned local `x` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:31:17 + │ +31 │ let q = x; + │ ^ + + +Diagnostics: +warning: Unused assignment to `z`. Consider removing or prefixing with an underscore: `_z` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:8:17 + │ +8 │ let z = y; + │ ^ + +warning: Unused assignment to `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:9:17 + │ +9 │ let q = x; + │ ^ + +warning: Unused assignment to `z`. Consider removing or prefixing with an underscore: `_z` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:17:17 + │ +17 │ let z = y; + │ ^ + +warning: Unused assignment to `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:18:17 + │ +18 │ let q = x; + │ ^ + +warning: Unused assignment to `z`. Consider removing or prefixing with an underscore: `_z` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:24:17 + │ +24 │ let z = y; + │ ^ + +warning: Unused assignment to `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:25:17 + │ +25 │ let q = x; + │ ^ + +warning: Unused assignment to `z`. Consider removing or prefixing with an underscore: `_z` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:30:17 + │ +30 │ let z = y; + │ ^ + +warning: Unused assignment to `q`. Consider removing or prefixing with an underscore: `_q` + ┌─ tests/unused-assignment/v1-locals/struct_use_before_assign.move:31:17 + │ +31 │ let q = x; + │ ^ diff --git a/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/struct_use_before_assign.move b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/struct_use_before_assign.move new file mode 100644 index 00000000000000..8d8997c73852d3 --- /dev/null +++ b/third_party/move/move-compiler-v2/tests/unused-assignment/v1-locals/struct_use_before_assign.move @@ -0,0 +1,33 @@ +module 0x876543::M { + struct R { f: u64, g: u64 } + + fun main() { + let g: u64; + let r = R { f: 3, g }; + let R { f: x, g: y } = r; + let z = y; + let q = x; + } + + fun main2() { + let x0: u64 = 0; + let y0: u64; + let r = R { f: x0, g: y0 }; + let R { f: x, g: y } = r; + let z = y; + let q = x; + } + + fun main3() { + let r: R; + let R { f: x, g: y } = r; + let z = y; + let q = x; + } + + fun main4() { + let R { f: x, g: y }; + let z = y; + let q = x; + } +} diff --git a/third_party/move/move-compiler-v2/tests/v1.matched b/third_party/move/move-compiler-v2/tests/v1.matched index 8ca914324fba72..25a816e67c53fb 100644 --- a/third_party/move/move-compiler-v2/tests/v1.matched +++ b/third_party/move/move-compiler-v2/tests/v1.matched @@ -138,6 +138,7 @@ move-compiler/tests/move_check/translated_ir_tests/move/commands/continue_outsid move-compiler/tests/move_check/translated_ir_tests/move/commands/else_assigns_if_doesnt.exp move-compiler-v2/tests/uninit-use-checker/v1-commands/else_assigns_if_doesnt.exp move-compiler/tests/move_check/translated_ir_tests/move/commands/if_assigns_else_doesnt.exp move-compiler-v2/tests/uninit-use-checker/v1-commands/if_assigns_else_doesnt.exp move-compiler/tests/move_check/translated_ir_tests/move/commands/if_assigns_no_else.exp move-compiler-v2/tests/uninit-use-checker/v1-commands/if_assigns_no_else.exp +move-compiler/tests/move_check/translated_ir_tests/move/commands/mixed_lvalue.exp move-compiler-v2/tests/unused-assignment/v1-commands/mixed_lvalue.exp move-compiler/tests/move_check/translated_ir_tests/move/commands/move_before_assign.exp move-compiler-v2/tests/uninit-use-checker/v1-commands/move_before_assign.exp move-compiler/tests/move_check/translated_ir_tests/move/commands/no_let_outside_if.exp move-compiler-v2/tests/checking/typing/v1-commands/no_let_outside_if.exp move-compiler/tests/move_check/translated_ir_tests/move/commands/pop_negative.exp move-compiler-v2/tests/checking/typing/v1-commands/pop_negative.exp @@ -206,9 +207,12 @@ move-compiler/tests/move_check/translated_ir_tests/move/generics/instantiation_l move-compiler/tests/move_check/liveness/mut_inline.exp move-compiler-v2/tests/live-var/mut_inline.exp move-compiler/tests/move_check/liveness/mut_ref.exp move-compiler-v2/tests/live-var/mut_ref.exp move-compiler/tests/move_check/liveness/unused_assignment.exp move-compiler-v2/tests/unused-assignment/v1-liveness/unused_assignment.exp +move-compiler/tests/move_check/locals/assign_partial_resource.exp move-compiler-v2/tests/unused-assignment/v1-locals/assign_partial_resource.exp +move-compiler/tests/move_check/locals/assign_resource.exp move-compiler-v2/tests/unused-assignment/v1-locals/assign_resource.exp move-compiler/tests/move_check/locals/drop_conditional.exp move-compiler-v2/tests/ability-check/v1-locals/drop_conditional.exp move-compiler/tests/move_check/locals/eliminate_temps.exp move-compiler-v2/tests/reference-safety/v1-locals/eliminate_temps.exp move-compiler/tests/move_check/locals/reassign_parameter.exp move-compiler-v2/tests/ability-check/v1-locals/reassign_parameter.exp +move-compiler/tests/move_check/locals/struct_use_before_assign.exp move-compiler-v2/tests/unused-assignment/v1-locals/struct_use_before_assign.exp move-compiler/tests/move_check/locals/unused_copyable.exp move-compiler-v2/tests/unused-assignment/v1-locals/unused_copyable.exp move-compiler/tests/move_check/locals/unused_resource.exp move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource.exp move-compiler/tests/move_check/locals/unused_resource_explicit_return.exp move-compiler-v2/tests/unused-assignment/v1-locals/unused_resource_explicit_return.exp diff --git a/third_party/move/move-compiler-v2/tests/v1.unmatched b/third_party/move/move-compiler-v2/tests/v1.unmatched index be6ec228f1ff02..f2ad6f0903cece 100644 --- a/third_party/move/move-compiler-v2/tests/v1.unmatched +++ b/third_party/move/move-compiler-v2/tests/v1.unmatched @@ -21,7 +21,6 @@ move-compiler/tests/move_check/commands/{ invalid_fallthrough2.move, invalid_fallthrough3.move, join_failure.move, - mixed_lvalue.move, while_move_local.move, while_move_local_2.move, } @@ -68,9 +67,6 @@ move-compiler/tests/move_check/liveness/{ trailing_semi_loops.move, } move-compiler/tests/move_check/locals/{ - assign_partial_resource.move, - assign_resource.move, - struct_use_before_assign.move, use_after_move_if.move, use_after_move_if_else.move, use_after_move_loop.move, diff --git a/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs b/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs index 1e518adba06b14..cc33da81712552 100644 --- a/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs +++ b/third_party/move/move-compiler-v2/tools/testdiff/src/main.rs @@ -102,6 +102,7 @@ static UNIT_PATH_REMAP: Lazy> = Lazy::new(|| { ("unit_test/test", "unit_test.unit_test"), ("unused-assignment/v1-locals", "locals"), ("unused-assignment/v1-liveness", "liveness"), + ("unused-assignment/v1-commands", "commands"), ("checking-lang-v1/v1-typing", "typing"), ("ability-check/v1-typing", "typing"), ("ability-check/v1-signer", "signer"),