diff --git a/rust-semantics/execution/let.md b/rust-semantics/execution/let.md index 0e56bce..6e990bb 100644 --- a/rust-semantics/execution/let.md +++ b/rust-semantics/execution/let.md @@ -48,6 +48,26 @@ module RUST-LET Values:Map => Values[NextId <- V] 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 ``` \ No newline at end of file diff --git a/tests/execution/let-expression.1.run b/tests/execution/let-expression.1.run new file mode 100644 index 0000000..940bf9b --- /dev/null +++ b/tests/execution/let-expression.1.run @@ -0,0 +1,4 @@ +new Let; +call Let.let_final; +return_value; +check_eq 100_u64 diff --git a/tests/execution/let-expression.2.run b/tests/execution/let-expression.2.run new file mode 100644 index 0000000..30f4c39 --- /dev/null +++ b/tests/execution/let-expression.2.run @@ -0,0 +1,4 @@ +new Let; +call Let.let_mut; +return_value; +check_eq 100_u64 diff --git a/tests/execution/let-expression.3.run b/tests/execution/let-expression.3.run new file mode 100644 index 0000000..0ee91a5 --- /dev/null +++ b/tests/execution/let-expression.3.run @@ -0,0 +1,4 @@ +new Let; +call Let.let_tuple; +return_value; +check_eq 100_u64 diff --git a/tests/execution/let-mut-expression.rs b/tests/execution/let-expression.rs similarity index 57% rename from tests/execution/let-mut-expression.rs rename to tests/execution/let-expression.rs index d889a10..05b3014 100644 --- a/tests/execution/let-mut-expression.rs +++ b/tests/execution/let-expression.rs @@ -4,7 +4,7 @@ use multiversx_sc::imports::*; #[multiversx_sc::contract] -pub trait LetMut { +pub trait Let { #[init] fn init(&self) { } @@ -12,9 +12,19 @@ pub trait LetMut { #[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 + } } diff --git a/tests/execution/let-final-expression.1.run b/tests/execution/let-final-expression.1.run deleted file mode 100644 index 1814298..0000000 --- a/tests/execution/let-final-expression.1.run +++ /dev/null @@ -1,4 +0,0 @@ -new LetFinal; -call LetFinal.let_final; -return_value; -check_eq 100_u64 diff --git a/tests/execution/let-final-expression.rs b/tests/execution/let-final-expression.rs deleted file mode 100644 index c74f9aa..0000000 --- a/tests/execution/let-final-expression.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![no_std] - -#[allow(unused_imports)] -use multiversx_sc::imports::*; - -#[multiversx_sc::contract] -pub trait LetFinal { - #[init] - fn init(&self) { - } - - #[upgrade] - fn upgrade(&self) {} - - fn let_final(&self) -> u64 { - let x = 100_u64; - x - } -} diff --git a/tests/execution/let-mut-expression.1.run b/tests/execution/let-mut-expression.1.run deleted file mode 100644 index 8a5ffe9..0000000 --- a/tests/execution/let-mut-expression.1.run +++ /dev/null @@ -1,4 +0,0 @@ -new LetMut; -call LetMut.let_mut; -return_value; -check_eq 100_u64