From c7c85c6c07f2425b910e1f584d20019677db303d Mon Sep 17 00:00:00 2001 From: Vineeth Kashyap Date: Tue, 12 Nov 2024 17:00:56 -0500 Subject: [PATCH] Document well defined eval order starting from Move 2 --- .../pages/en/build/smart-contracts/book/move-2.mdx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/nextra/pages/en/build/smart-contracts/book/move-2.mdx b/apps/nextra/pages/en/build/smart-contracts/book/move-2.mdx index 600718927..f587d7087 100644 --- a/apps/nextra/pages/en/build/smart-contracts/book/move-2.mdx +++ b/apps/nextra/pages/en/build/smart-contracts/book/move-2.mdx @@ -2,7 +2,7 @@ The Move 2 language releases are described on this page. The reference documentation of the new features is integrated into the book, and marked in the text with "_Since language version 2.n_". -## Move 2.1 +## Move 2.1 The Move 2.1 language release adds the following features to Move: @@ -12,7 +12,7 @@ The Move 2.1 language release adds the following features to Move: - **Underscore function parameters are wildcards, not symbols** Function parameters named `_` no longer act like variables: they do not bind a value, and multiple such parameters to a function does not cause a conflict. Using `_` in a value expression will yield an error, as it has no value. This makes the behavior of `_` more like the wildcard it is in patterns and let expressions, where it does not bind a value. -## Move 2.0 +## Move 2.0 The Move 2.0 language release adds the following features to Move: @@ -20,7 +20,7 @@ The Move 2.0 language release adds the following features to Move: - **Receiver Style Functions** add the ability to call functions in the familiar notation `value.func(arg)`. They are documented in [this section](functions.mdx#dot-receiver-function-call-style). -- **Index Notation** allows to access [elements of vectors](vector.mdx#index-notation-for-vectors) and of [resource storage](global-storage-operators.mdx#index-notation-for-storage-operators) with notations like `&mut vector[index]`, or `&mut Resource[addr]`, respectively. +- **Index Notation** allows access to [elements of vectors](vector.mdx#index-notation-for-vectors) and of [resource storage](global-storage-operators.mdx#index-notation-for-storage-operators) with notations like `&mut vector[index]`, or `&mut Resource[addr]`, respectively. - **Positional Structs** allow to define wrapper types such as `struct Wrapped(u64)`. Positional structs are described [here](structs-and-resources.mdx#positional-structs). Enum variants are also allowed to be positional. @@ -29,5 +29,9 @@ The Move 2.0 language release adds the following features to Move: - **Package visibility** allows to declare a function to be visible anywhere inside, but not outside a package. Friend functions continue to be supported, although package visibility is in many cases more suitable. As a more concise notation, package and friend functions can be simply declared as `package fun` or `friend fun`, respectively, instead of the longer `public(package) fun` and `public(friend) fun`. This feature is documented [here](functions.mdx#package-visibility). - **Assert abort code optional** The `assert!` macro can now be used with just one argument, omitting the abort code, in which case a default code will be chosen. See also [here](abort-and-assert.mdx#assert). - + - **New Cast Syntax** Until now, casts had to always be in parentheses, requiring code like `function((x as u256))`. This requirement is now dropped and casts can be top-level expressions without parenthesis, as in `function(x as u256)`. One still needs to write `(x as u64) + (y as u64)` in expressions. This similarly applies to the new enum variant test, `data is VersionedData::V1`. + +- **Well-defined evaluation order** The evaluation order in the cases below is now well-defined (these were previously unspecified): + - The (a) arguments to a function call, and the (b) operand expressions in a binary operation, are both evaluated from left-to-right. + - Given a "mutate" expression (see [mutating through a reference](variables.mdx#mutating-through-a-reference)) of the form `*lexp = rexp`, where `lexp` is an expression of type `&mut T` and `rexp` is an expression of type `T`, `rexp` is evaluated first, followed by `lexp`.