Skip to content

Commit

Permalink
Enabling assignments on tuples with let expressions (#107)
Browse files Browse the repository at this point in the history
* Enabling assignments on tuples with let expressions

* Addressing comments
  • Loading branch information
ACassimiro authored Sep 27, 2024
1 parent 5481094 commit c7e509e
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 28 deletions.
20 changes: 20 additions & 0 deletions rust-semantics/execution/let.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ module RUST-LET
<values> Values:Map => Values[NextId <- V] </values>
requires notBool mayBeDefaultTypedInt(V)
// Handling tuple assignments
rule
let (Variable:PatternNoTopAlt | .PatternNoTopAlts , RemainingToAssign:Patterns):TuplePattern
= ptrValue(_,tuple(Val:Value, ValList:ValueList)) ;
=>
let Variable = ptrValue(null, Val);
~> let (RemainingToAssign:Patterns:TuplePatternItems):TuplePattern
= ptrValue(null, tuple(ValList));
rule
let (.Patterns):TuplePattern = ptrValue(_,tuple(.ValueList));
=> .K
// Handles the case where the tuple pattern on the let expression has an extra comma, removing it
rule
let (Ps:Patterns,):TuplePattern = V:PtrValue;
=> let (Ps):TuplePattern = V;
endmodule
```
4 changes: 4 additions & 0 deletions tests/execution/let-expression.1.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
new Let;
call Let.let_final;
return_value;
check_eq 100_u64
4 changes: 4 additions & 0 deletions tests/execution/let-expression.2.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
new Let;
call Let.let_mut;
return_value;
check_eq 100_u64
4 changes: 4 additions & 0 deletions tests/execution/let-expression.3.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
new Let;
call Let.let_tuple;
return_value;
check_eq 100_u64
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
use multiversx_sc::imports::*;

#[multiversx_sc::contract]
pub trait LetMut {
pub trait Let {
#[init]
fn init(&self) {
}

#[upgrade]
fn upgrade(&self) {}

fn let_final(&self) -> u64 {
let x = 100_u64;
x
}

fn let_mut(&self) -> u64 {
let mut x = 99_u64;
x = 100_u64;
x
}

fn let_tuple(&self) -> u64 {
let (x, y, z, w,) = (100_u64, 99_u64, 98_u64, 97_u64);
x
}
}
4 changes: 0 additions & 4 deletions tests/execution/let-final-expression.1.run

This file was deleted.

19 changes: 0 additions & 19 deletions tests/execution/let-final-expression.rs

This file was deleted.

4 changes: 0 additions & 4 deletions tests/execution/let-mut-expression.1.run

This file was deleted.

0 comments on commit c7e509e

Please sign in to comment.