Skip to content

Commit

Permalink
fixup! move stdlib: type_info::type_name()
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse committed Jul 21, 2022
1 parent 59be05a commit bd3e3e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions aptos-move/framework/aptos-stdlib/sources/type_info.move
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module aptos_std::type_info {
}

public native fun type_of<T>(): TypeInfo;
public native fun full_name<T>(): string::String;
public native fun type_name<T>(): string::String;

#[test]
fun test() {
Expand All @@ -31,29 +31,29 @@ module aptos_std::type_info {
}

#[test]
fun test_full_name() {
fun test_type_name() {
use aptos_std::table::Table;

assert!(full_name<bool>() == string::utf8(b"bool"), 0);
assert!(full_name<u8>() == string::utf8(b"u8"), 1);
assert!(full_name<u64>() == string::utf8(b"u64"), 2);
assert!(full_name<u128>() == string::utf8(b"u128"), 3);
assert!(full_name<address>() == string::utf8(b"address"), 4);
assert!(full_name<signer>() == string::utf8(b"signer"), 5);
assert!(type_name<bool>() == string::utf8(b"bool"), 0);
assert!(type_name<u8>() == string::utf8(b"u8"), 1);
assert!(type_name<u64>() == string::utf8(b"u64"), 2);
assert!(type_name<u128>() == string::utf8(b"u128"), 3);
assert!(type_name<address>() == string::utf8(b"address"), 4);
assert!(type_name<signer>() == string::utf8(b"signer"), 5);

// vector
assert!(full_name<vector<u8>>() == string::utf8(b"vector<u8>"), 6);
assert!(full_name<vector<vector<u8>>>() == string::utf8(b"vector<vector<u8>>"), 7);
assert!(full_name<vector<vector<TypeInfo>>>() == string::utf8(b"vector<vector<0x1::type_info::TypeInfo>>"), 8);
assert!(type_name<vector<u8>>() == string::utf8(b"vector<u8>"), 6);
assert!(type_name<vector<vector<u8>>>() == string::utf8(b"vector<vector<u8>>"), 7);
assert!(type_name<vector<vector<TypeInfo>>>() == string::utf8(b"vector<vector<0x1::type_info::TypeInfo>>"), 8);


// struct
assert!(full_name<TypeInfo>() == string::utf8(b"0x1::type_info::TypeInfo"), 9);
assert!(full_name<
assert!(type_name<TypeInfo>() == string::utf8(b"0x1::type_info::TypeInfo"), 9);
assert!(type_name<
Table<
TypeInfo,
Table<u8, vector<TypeInfo>>
>
>() == string::utf8(b"0x1::table::Table<0x1::type_info::TypeInfo, 0x1::table::Table<u8, vector<0x1::type_info::TypeInfo>>"), 10);
>() == string::utf8(b"0x1::table::Table<0x1::type_info::TypeInfo, 0x1::table::Table<u8, vector<0x1::type_info::TypeInfo>>>"), 10);
}
}
2 changes: 1 addition & 1 deletion aptos-move/framework/src/natives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn all_natives(framework_addr: AccountAddress) -> NativeFunctionTable {
signature::native_secp256k1_recover,
),
("type_info", "type_of", type_info::type_of),
("type_info", "full_name", type_info::full_name),
("type_info", "type_name", type_info::type_name),
("hash", "sip_hash", hash::native_sip_hash),
];
NATIVES
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/src/natives/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn type_of(
}

/// Returns a string representing the TypeTag of the parameter.
pub fn full_name(
pub fn type_name(
context: &mut NativeContext,
ty_args: Vec<Type>,
arguments: VecDeque<Value>,
Expand Down

0 comments on commit bd3e3e7

Please sign in to comment.