Skip to content

Commit dd95019

Browse files
committed
Addressing reviewer comments
1 parent 2f321fc commit dd95019

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

apps/nextra/pages/en/build/smart-contracts/book/abort-and-assert.mdx

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ if (condition) () else abort code
7676
```
7777

7878
Since Move 2.0, `assert` without an error code is supported. If this assert is used, the
79-
abort code `0xD8CA26CBD9BE00000000` is generated.
79+
abort code `0xCA26CBD9BE0B0000` is generated. In terms of the `std::error` convention, this code has
80+
category `std::error::INTERNAL` and reason `0`.
8081

8182
`assert` is more commonly used than just `abort` by itself. The `abort` examples above can be
8283
rewritten using `assert`

apps/nextra/pages/en/build/smart-contracts/book/enums.mdx

+9-11
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ Notice above that the value matched is an immutable reference to an enum value.
9595
```move
9696
fun scale_radius(self: &mut Rectangle, factor: u64) {
9797
match (self) {
98-
Circle{radius} => *radius = *radius * factor,
99-
_ => {} // do nothing if not a Circle
98+
Circle{radius: r} => *r = *r * factor,
99+
_ => {} // do nothing if not a Circle
100100
}
101101
}
102102
```
@@ -106,19 +106,17 @@ The patterns provided in the match expression are evaluated sequentially, in ord
106106
Patterns can be nested and contain conditions, as in the following example:
107107

108108
```move
109-
use Result::*;
110109
let r : Result<Result<u64>> = Ok(Err(42));
111110
let v = match (r)) {
112111
Ok(Err(c)) if c < 42 => 0,
113112
Ok(Err(c)) if c >= 42 => 1,
114113
Ok(_) => 2,
115-
_ => 3
114+
_ => 3
115+
};
116116
assert!(v == 1);
117117
```
118118

119-
Notice that in the above example, the last match clause (`_`) covers both patterns `Ok(Err(_))` and `Err(_)`. Although at execution time, the earlier clauses may match `Ok(Err(c))` for all values of `c`, the compiler cannot be sure all cases are covered due to the conditionals: conditions in match expressions are not considered when tracking coverage. Thus the first two clauses in the match expression above are not sufficient for match completeness, and an additional clause is required to avoid a compiler error.
120-
121-
Notice that while match completeness is enforced by the compiler, at runtime it may not be guaranteed if code is upgraded. See the discussion of upgrade compatibility of enums here.
119+
Notice that in the above example, the last match clause (`_`) covers both patterns `Ok(Err(_))` and `Err(_)`. Although at execution time, the earlier clauses match `Ok(Err(c))` for all values of `c`, the compiler cannot be sure all cases are covered due to the conditionals: conditions in match expressions are not considered when tracking coverage. Thus the first two clauses in the match expression above are not sufficient for match completeness, and an additional clause is required to avoid a compiler error.
122120

123121
## Testing Enum Variants
124122

@@ -135,7 +133,6 @@ The operator allows specifying a list of variants, separated by "`|`" characters
135133
assert!(data is V1|V2);
136134
```
137135

138-
139136
## Selecting From Enum Values
140137

141138
It is possible to directly select a field from an enum value. Recall the definition of versioned data:
@@ -153,19 +150,20 @@ One can write code as below to directly select the fields of variants:
153150
let s: String;
154151
let data1 = VersionedData::V1{name: s};
155152
let data2 = VersionedData::V2{name: s, age: 20};
156-
assert!(data1 is VersionData::V2);
157153
assert!(data1.name == data2.name)
158-
assert!(data2.age == 20); // Note that `data1.age` will abort!
154+
assert!(data2.age == 20);
159155
```
160156

161157
Notice that field selection aborts if the enum value has no variant with the given field. This is the case for `data1.age`.
158+
The abort code used for this case is `0xCA26CBD9BE0B0001`. In terms of the `std::error` convention, this code has
159+
category `std::error::INTERNAL` and reason `1`.
162160

163161
Field selection is only possible if the field is uniquely named and typed throughout all variants. Thus, the following yields a compile time error:
164162

165163
```move
166164
enum VersionedData has key {
167165
V1{name: String}
168-
V3{name: u64}
166+
V2{name: u64}
169167
}
170168
171169
data.name

apps/nextra/pages/en/build/smart-contracts/book/functions.mdx

+7-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ A `package` function can be only called within the same package. The notion of a
8888
defined by the hosting environment of Move, and not explicit in the language. Typically, the package
8989
is defined by a manifest file `Move.toml` which is processed by the build environment.
9090

91-
The following works, provided the two modules belong to the same package:
91+
The following works, provided the two modules belong to the same package and are at the same address:
9292

9393
```move
9494
module 0x42::m {
@@ -104,7 +104,10 @@ module 0x42::other {
104104

105105
An attempt to access `0x42::m::foo` from another package will fail at compile time.
106106

107-
Notice that package visibility is a compile time concept which is reduced by the compiler to friend visibility (described [below](#friend-visibility)), which can be verified by the Move VM.
107+
In addition to the notation `package fun`, also the longer notation `public(package) fun` is supported.
108+
109+
Notice that package visibility is a compile time concept which is reduced by the compiler to friend visibility (described [below](#friend-visibility)), which can be verified by the Move VM. The Move VM guarantees that friend functions
110+
cannot be called across address boundaries, independent of what package system a compilation environment supports.
108111

109112

110113
#### `public(friend)` visibility
@@ -114,9 +117,9 @@ _Since Language Version 2.0_, `friend fun` replaces `public(friend) fun`. The ol
114117
The `public(friend)` visibility modifier is a more restricted form of the `public` modifier to give more control about where a function can be used. A `public(friend)` function can be called by:
115118

116119
- other functions defined in the same module, or
117-
- functions defined in modules which are explicitly specified in the **friend list** (see [Friends](friends.mdx) on how to specify the friend list).
120+
- functions defined in modules which are explicitly specified in the **friend list** (see [Friends](friends.mdx) on how to specify the friend list), and which reside at the same address.
118121

119-
Note that since we cannot declare a script to be a friend of a module, the functions defined in scripts can never call a `public(friend)` function.
122+
Note that since we cannot declare a script to be a friend of a module, the functions defined in scripts can never call a `public(friend)` function.
120123

121124
```move
122125
address 0x42 {

apps/nextra/pages/en/build/smart-contracts/book/global-storage-operators.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ The table below gives an overview of index notations for storage:
267267
| `&T[address].field` | `&borrow_global<T>(address).field` |
268268
| `&mut T[address].field` | `&mut borrow_global_mut<T>(address).field` |
269269
| `T[address].field` | `borrow_global<T>(address).field` |
270-
| `T[address].field = x` | `*borrow_global_mut<T>(address).field = x` |
270+
| `T[address].field = x` | `borrow_global_mut<T>(address).field = x` |
271271

272272
Here `T` represents a generic resource type that can take type parameters.
273273

apps/nextra/pages/en/build/smart-contracts/book/structs-and-resources.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ module 0x2::m {
487487
struct Foo{ x: u8, y: u16, z: u32 }
488488
struct Bar(u8, u16, u32);
489489
490-
fun foo_get_x(self: &Foo): u8 {
491-
let Foo{x, ..} = self;
490+
fun foo_get_x(self: &Foo): u16 {
491+
let Foo{y, ..} = self;
492492
x
493493
}
494494

apps/nextra/pages/en/build/smart-contracts/book/vector.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ The table below gives an overview of index notations for vectors:
157157
| `&v[i]` | `vector::borrow(&v, i)` |
158158
| `&mut v[i]` | `vector::borrow_mut(&mut v, i)` |
159159
| `v[i]` | `*vector::borrow(&v, i)` |
160-
| `v[i] = x` | `*vector::borrow(&v, i) = x` |
160+
| `v[i] = x` | `*vector::borrow_mut(&mut v, i) = x` |
161161
| `&v[i].field` | `&vector::borrow(&v, i).field` |
162162
| `&mut v[i].field` | `&mut vector::borrow_mut(&mut v, i).field` |
163-
| `v[i].field` | `vector::borrow(&v, i).field` |
164-
| `v[i].field = x` | `vector::borrow_mut(&mut v, i).field = x` |
163+
| `v[i].field` | `vector::borrow(&v, i).field` |
164+
| `v[i].field = x` | `vector::borrow_mut(&mut v, i).field = x` |
165165

166166
As an example, here is a bubble sort algorithm for vectors using index notation:
167167

0 commit comments

Comments
 (0)