Skip to content

Commit

Permalink
Addressing code review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethk committed Apr 10, 2024
1 parent 071dbf2 commit fdc19d3
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Diagnostics:
error: the left-hand side has 2 items but the right-hand side provided 1
error: the left-hand side has 1 item but the right-hand side provided 2
┌─ tests/bytecode-generator/wildcard1.move:7:13
7 │ let _ = tup();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// -- Model dump before bytecode pipeline
module 0xc0ffee::m {
struct S {
x: u64,
y: u64,
}
public fun test() {
{
let s: m::S = pack m::S(3, 4);
{
let m::S{ x: _, y: _ }: m::S = s;
Tuple()
}
}
}
} // end 0xc0ffee::m

============ initial bytecode ================

[variant baseline]
public fun m::test() {
var $t0: m::S
var $t1: u64
var $t2: u64
var $t3: u64
var $t4: u64
0: $t1 := 3
1: $t2 := 4
2: $t0 := pack m::S($t1, $t2)
3: ($t3, $t4) := unpack m::S($t0)
4: return ()
}


============ bytecode verification succeeded ========
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module 0xc0ffee::m {
struct S {
x: u64,
y: u64
}

public fun test() {
let s = S {x: 3, y: 4};
let S {x: _, y: _} = s;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -- Model dump before bytecode pipeline
module 0xc0ffee::m {
public fun test2(): u64 {
{
let x: u64 = 40;
{
let (y: u64, _): (u64, u64) = Tuple(Move(x), x);
y
}
}
}
} // end 0xc0ffee::m

============ initial bytecode ================

[variant baseline]
public fun m::test2(): u64 {
var $t0: u64
var $t1: u64
var $t2: u64
var $t3: u64
var $t4: u64
0: $t1 := 40
1: $t3 := move($t1)
2: $t2 := infer($t3)
3: $t4 := infer($t1)
4: $t0 := infer($t2)
5: return $t0
}


Diagnostics:
error: cannot move local `x` since it is still in use
┌─ tests/bytecode-generator/wildcard6.move:4:23
4 │ let (y, _) = (move x, x);
│ ------ ^^^^^^ attempted to move here
│ │
│ used here
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module 0xc0ffee::m {
public fun test2(): u64 {
let x = 40;
let (y, _) = (move x, x);
y
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

Diagnostics:
warning: Unused local variable `q`. Consider removing or prefixing with an underscore: `_q`
┌─ tests/bytecode-generator/wildcard7.move:6:17
6 │ let (_, q) = (x, z);
│ ^

// -- Model dump before bytecode pipeline
module 0xc0ffee::m {
public fun test(): u8 {
{
let x: u8 = 40;
{
let y: u8 = Move(x);
{
let (_, q: u64): (u8, u64) = Tuple(x, 30);
y
}
}
}
}
} // end 0xc0ffee::m

============ initial bytecode ================

[variant baseline]
public fun m::test(): u8 {
var $t0: u8
var $t1: u8
var $t2: u8
var $t3: u64
var $t4: u8
var $t5: u64
0: $t1 := 40
1: $t2 := move($t1)
2: $t4 := infer($t1)
3: $t5 := 30
4: $t3 := infer($t5)
5: $t0 := infer($t2)
6: return $t0
}


Diagnostics:
error: cannot move local `x` since it is still in use
┌─ tests/bytecode-generator/wildcard7.move:5:17
5 │ let y = move x;
│ ^^^^^^ attempted to move here
6 │ let (_, q) = (x, z);
│ ------ used here
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module 0xc0ffee::m {
public fun test(): u8 {
let x = 40;
let z = 30;
let y = move x;
let (_, q) = (x, z);
y
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ error: the left-hand side has 2 items but the right-hand side provided 0
13 │ (_, _) = ();
│ ^^^^^^

error: the left-hand side has 0 items but the right-hand side provided 1
error: the left-hand side has 1 item but the right-hand side provided 0
┌─ tests/checking/typing/v1-commands/pop_weird.move:14:9
14 │ (_) = ();
Expand Down
2 changes: 1 addition & 1 deletion third_party/move/move-model/src/builder/exp_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ impl<'env, 'translator, 'module_translator> ExpTranslator<'env, 'translator, 'mo
let specialized_expected_type = self.subs.specialize(expected_type);
if let Type::Tuple(tys) = specialized_expected_type {
if tys.len() != 1 {
self.error(loc, &context.arity_mismatch(false, 1, tys.len()));
self.error(loc, &context.arity_mismatch(false, tys.len(), 1));
return self.new_error_pat(loc);
}
}
Expand Down

0 comments on commit fdc19d3

Please sign in to comment.