-
Notifications
You must be signed in to change notification settings - Fork 145
[reference] Reduce reading ambiguity #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,8 +68,8 @@ use std::option::some as s; | |
|
|
||
| fun new_vec(): vector<std::option::Option<u8>> { | ||
| let mut v = vector[]; | ||
| vector::push_back(&mut v, s(0)); | ||
| vector::push_back(&mut v, std::option::none()); | ||
| push_back(&mut v, s(0)); | ||
| push_back(&mut v, std::option::none()); | ||
| v | ||
| } | ||
| ``` | ||
|
|
@@ -163,8 +163,8 @@ use std::vector; | |
|
|
||
| fun new_vec(): vector<Option<u8>> { | ||
| let mut v = vector[]; | ||
| vector::push_back(&mut v, 0); | ||
| vector::push_back(&mut v, 10); | ||
| vector::push_back(&mut v, some(0)); | ||
| vector::push_back(&mut v, none()); | ||
| v | ||
| } | ||
|
|
||
|
|
@@ -183,9 +183,9 @@ You can add `use` declarations to the beginning of any expression block | |
| ```move | ||
| module a::example; | ||
|
|
||
| fun new_vec(): vector<Option<u8>> { | ||
| fun new_vec(): vector<std::option::Option<u8>> { | ||
| use std::vector::push_back; | ||
| use std::option::{Option, some, none}; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you remove
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I understand, Of course, I just made the changes based on my understanding. If my understanding itself is wrong, please correct me.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To illustrate further, I wrote a small example: module examples::a {
public struct MyOption<T> has copy, drop, store {
vec: vector<T>
}
public fun some<T>(e: T): MyOption<T> {
MyOption {
vec: vector[e]
}
}
public fun none<T>(): MyOption<T> {
MyOption {
vec: vector[]
}
}
}
module examples::b {
// If you replace the two commented lines below, you will get an error.
// fun new_vec(): vector<MyOption<u8>> {
// use examples::a::{MyOption, some, none};
fun new_vec(): vector<examples::a::MyOption<u8>> {
use examples::a::{some, none};
let mut v = vector[];
v.push_back(some(0));
v.push_back(none());
v
}
} |
||
| use std::option::{some, none}; | ||
|
|
||
| let mut v = vector[]; | ||
| push_back(&mut v, some(0)); | ||
|
|
@@ -200,10 +200,10 @@ block. | |
| ```move | ||
| module a::example; | ||
|
|
||
| fun new_vec(): vector<Option<u8>> { | ||
| fun new_vec(): vector<std::option::Option<u8>> { | ||
| let result = { | ||
| use std::vector::push_back; | ||
| use std::option::{Option, some, none}; | ||
| use std::option::{some, none}; | ||
|
|
||
| let mut v = vector[]; | ||
| push_back(&mut v, some(0)); | ||
|
|
@@ -217,10 +217,10 @@ fun new_vec(): vector<Option<u8>> { | |
| Attempting to use the alias after the block ends will result in an error | ||
|
|
||
| ```move | ||
| fun new_vec(): vector<Option<u8>> { | ||
| fun new_vec(): vector<std::option::Option<u8>> { | ||
| let mut result = { | ||
| use std::vector::push_back; | ||
| use std::option::{Option, some, none}; | ||
| use std::option::{some, none}; | ||
|
|
||
| let mut v = vector[]; | ||
| push_back(&mut v, some(0)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
option::someThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or add a
usestatement above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relevant
usestatement is below, which is what this example needs to demonstrate.