diff --git a/third_party/move/move-compiler-v2/src/bytecode_generator.rs b/third_party/move/move-compiler-v2/src/bytecode_generator.rs index 9abbb8fd15c1ab..2aa7afbd7533d4 100644 --- a/third_party/move/move-compiler-v2/src/bytecode_generator.rs +++ b/third_party/move/move-compiler-v2/src/bytecode_generator.rs @@ -1271,8 +1271,13 @@ impl<'env> Generator<'env> { ) { match pat { Pattern::Wildcard(_) => { - // Nothing to do - // TODO(#12475) Should we copy to a temp here? + let ty = self.temp_type(arg).to_owned(); + let temp = self.new_temp(ty); + // Assign to a temporary to allow stackless bytecode checkers to report any errors + // due to the assignment. + self.emit_with(id, |attr| { + Bytecode::Assign(attr, temp, arg, AssignKind::Inferred) + }) }, Pattern::Var(var_id, sym) => { let local = self.find_local_for_pattern(*var_id, *sym, next_scope); diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/moved_var_not_simplified3.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/moved_var_not_simplified3.exp index 3755b319d9967a..fa669c34cd5839 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/moved_var_not_simplified3.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/moved_var_not_simplified3.exp @@ -21,11 +21,20 @@ public fun m::test(): u8 { var $t0: u8 var $t1: u8 var $t2: u8 + var $t3: u8 0: $t1 := 40 1: $t2 := move($t1) - 2: $t0 := infer($t2) - 3: return $t0 + 2: $t3 := infer($t1) + 3: $t0 := infer($t2) + 4: return $t0 } -============ bytecode verification succeeded ======== +Diagnostics: +error: cannot move local `x` since it is still in use + ┌─ tests/bytecode-generator/moved_var_not_simplified3.move:4:17 + │ +4 │ let y = move x; + │ ^^^^^^ attempted to move here +5 │ let _ = x; + │ - used here diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard2.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard2.exp index 658944ca7dfdf8..dd31701d7fac8c 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard2.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard2.exp @@ -15,9 +15,16 @@ module 0xc0ffee::m { [variant baseline] public fun m::baz() { - var $t0: u64 [unused] - 0: return () + var $t0: u64 + var $t1: u64 + 0: $t1 := infer($t0) + 1: return () } -============ bytecode verification succeeded ======== +Diagnostics: +error: use of unassigned local `x` + ┌─ tests/bytecode-generator/wildcard2.move:4:13 + │ +4 │ let _ = x; + │ ^ diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard3.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard3.exp index 12e852f33c32fd..8b17531c4b9e88 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard3.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard3.exp @@ -26,27 +26,31 @@ module 0xc0ffee::m { public fun m::bar() { var $t0: m::S var $t1: bool + var $t2: m::S 0: $t1 := false 1: $t0 := pack m::S($t1) - 2: return () + 2: $t2 := infer($t0) + 3: return () } [variant baseline] public fun m::foo($t0: m::S) { - 0: return () + var $t1: m::S + 0: $t1 := infer($t0) + 1: return () } Diagnostics: -error: local `s` of type `m::S` does not have the `drop` ability - ┌─ tests/bytecode-generator/wildcard3.move:5:18 +error: value of type `m::S` does not have the `drop` ability + ┌─ tests/bytecode-generator/wildcard3.move:5:13 │ 5 │ let _ = s; - │ ^ implicitly dropped here since it is no longer used + │ ^ implicitly dropped here since it is no longer used -error: local `s` of type `m::S` does not have the `drop` ability - ┌─ tests/bytecode-generator/wildcard3.move:9:17 - │ -9 │ let s = S{}; - │ ^^^ implicitly dropped here since it is no longer used +error: value of type `m::S` does not have the `drop` ability + ┌─ tests/bytecode-generator/wildcard3.move:10:13 + │ +10 │ let _ = s; + │ ^ implicitly dropped here since it is no longer used diff --git a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard4.exp b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard4.exp index 28e3343b789224..a09037fa0a35b1 100644 --- a/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard4.exp +++ b/third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard4.exp @@ -26,14 +26,16 @@ fun m::test() { var $t1: &mut u64 var $t2: &mut u64 var $t3: &u64 - var $t4: u64 + var $t4: &u64 + var $t5: u64 0: $t0 := 3 1: $t1 := borrow_local($t0) 2: $t2 := borrow_local($t0) 3: $t3 := freeze_ref($t2) - 4: $t4 := 4 - 5: write_ref($t1, $t4) - 6: return () + 4: $t4 := infer($t3) + 5: $t5 := 4 + 6: write_ref($t1, $t5) + 7: return () }