-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move 2024] Added implicit/default aliases. Fixed edgecase with built…
…in names (#16339) ## Description - Fixed an edge case with builtin names, where `<builtin>` would resolve to a module after a `use a::<builtin>` - Added implicit aliases for `std` and `sui` ## Test Plan New tests --- If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section. ### Type of Change (Check all that apply) - [ ] protocol change - [X] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes Move 2024 now has the following implicit aliases ``` use std::vector; use std::option::{Self, Option}; use sui::object::{Self, ID, UID}; use sui::transfer; use sui::tx_context::{Self, TxContext}; ```
- Loading branch information
Showing
5 changed files
with
200 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ve/crates/move-compiler/tests/move_2024/expansion/always_module_member_without_chain.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// without a chain, we always assume a module member | ||
module a::S { | ||
public struct S() | ||
// does not resolve to the module | ||
fun id(s: S): S { s } | ||
} | ||
// extra care given for builtins | ||
#[allow(unused_use)] | ||
module a::u64 { | ||
use a::u64; // unused | ||
const C: u64 = 0; | ||
fun new(): u64 { 0 } | ||
} |
11 changes: 11 additions & 0 deletions
11
...rnal-crates/move/crates/move-compiler/tests/move_2024/expansion/implicit_std_aliases.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// if std is defined, the implicit aliases of | ||
// use std::vector; | ||
// use std::option::{Self, Option}; | ||
module a::m { | ||
public struct S { f: Option<u64> } | ||
fun wow(): vector<Option<u64>> { | ||
let mut v = vector::empty(); | ||
vector::push_back(&mut v, option::none()); | ||
v | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...rnal-crates/move/crates/move-compiler/tests/move_2024/expansion/leading_builtin_name.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module a::t1 { | ||
use std::vector; | ||
|
||
public entry fun ascii_vec_arg(v: vector<u8>) { | ||
assert!(vector::is_empty(&v), 0); | ||
} | ||
} | ||
|
||
module a::t2 { | ||
// implicit use std::vector; | ||
|
||
public entry fun ascii_vec_arg(v: vector<u8>) { | ||
assert!(vector::is_empty(&v), 0); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...es/move/crates/move-compiler/tests/sui_mode/move_2024/expansion/implicit_sui_aliases.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// sui mode has the implicit asliases: | ||
// use sui::object::{Self, ID, UID}; | ||
// use sui::transfer; | ||
// use sui::tx_context::{Self, TxContext}; | ||
module a::m { | ||
public struct S has key { id: UID, other: ID } | ||
public fun create(ctx: &mut TxContext) { | ||
transfer::transfer( | ||
S { id: object::new(ctx), other: object::id_from_address(@0) }, | ||
tx_context::sender(ctx), | ||
) | ||
} | ||
} | ||
|
||
|
||
// we don't link out to the sui framework | ||
module sui::object { | ||
public struct ID has copy, drop, store { | ||
bytes: address | ||
} | ||
|
||
public struct UID has store { | ||
id: ID, | ||
} | ||
|
||
public fun new(_: &mut TxContext): UID { abort 0 } | ||
public fun id_from_address(_: address): ID { abort 0 } | ||
} | ||
module sui::transfer { | ||
public fun transfer<T: key>(_: T, _: address) { abort 0 } | ||
} | ||
module sui::tx_context { | ||
public struct TxContext has drop {} | ||
public fun sender(_: &TxContext): address { @0 } | ||
} |