move-language / move

Apache License 2.0
2.25k stars 684 forks source link

[Bug] std::type_name::into_string does not handle multiple generics well #916

Closed PaulFidika closed 1 year ago

PaulFidika commented 1 year ago

When I define a struct like this:

struct SillyStruct<phantom A, phantom B, phantom C> has drop { }

And then try to get the type name, like this:

sui_utils::encode::type_name<SillyStruct<SUI, u64, vector<u8>>>()

I get an output like this:

77799ff1bc7ca73c5d9e8b5ff85362a5681963d4::encode_test::SillyStruct<0000000000000000000000000000000000000002::sui::SUIu64vector<u8>>

The problem is that the generics are all smooshed together; you would expect "SUI, u64, vector" (spaces) or "SUI,u64,vector" (no spaces). But as it is now it's impossible to parse the generics, which is something I'm trying to do. This is only an issue for structs with multiple generics, which are uncommon, which is probably why it hasn't been encountered yet.

sui_utils can be found here, although it's simply calling into the existing std::type_name::get() function: https://github.com/capsule-craft/capsules/blob/master/packages/sui_utils/sources/encode.move

Thanks.