Skip to content

Commit

Permalink
Document well defined eval order starting from Move 2
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethk committed Nov 13, 2024
1 parent aedd31c commit c7c85c6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions apps/nextra/pages/en/build/smart-contracts/book/move-2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -12,15 +12,15 @@ 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:

- **Enum Types** add the option to define different variants of data layout in one storable type. They are documented in the [Enum Type section](enums.mdx).

- **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.

Expand All @@ -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`.

0 comments on commit c7c85c6

Please sign in to comment.