-
Notifications
You must be signed in to change notification settings - Fork 244
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
Invalid generation of types with >1 generic #550
Comments
The more I dig, the deeper the dip. It might definitely be a |
Thanks for reporting this, and please do let me know what you find from your digging! I'm not sure I'll have much chance to look at this for a while as I'm away next week, but @ascjones might have know more about it offhand! |
Can you provide the full test case please @hussein-aitlahcen? |
#[test]
fn generics() {
#[allow(unused)]
#[derive(TypeInfo)]
struct Foo<T, U, V, W> {
a: T,
b: U,
c: V,
d: W
}
#[allow(unused)]
#[derive(TypeInfo)]
struct Bar {
p: Foo<u32, u32, u64, u128>,
q: Foo<u8, u8, u8, u8>,
}
env_logger::init();
let mut registry = Registry::new();
registry.register_type(&meta_type::<Bar>());
log::info!("{:#?}", registry);
let portable_types: PortableRegistry = registry.into();
log::info!("{:#?}", portable_types);
let type_gen = TypeGenerator::new(
&portable_types,
"root",
Default::default(),
Default::default(),
);
let types = type_gen.generate_types_mod();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();
assert_eq!(
tests_mod.into_token_stream().to_string(),
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
pub struct Bar {
pub p: root::subxt_codegen::types::tests::Foo<::core::primitive::u32, ::core::primitive::u32, ::core::primitive::u64, ::core::primitive::u128>,
pub q: root::subxt_codegen::types::tests::Foo<::core::primitive::u8, ::core::primitive::u8, ::core::primitive::u8, ::core::primitive::u8>,
}
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
pub struct Foo<_0, _1, _2, _3> {
pub a: _0,
pub b: _1,
pub c: _2,
pub d: _3,
}
}
}
.to_string()
)
} Result
|
@ascjones worth to mention, I figured out this using |
At a glance there seems to be a bug where concrete type for all params are the same |
It does work if you instantiate with distinct types, used |
Okay thanks for confirming that. I don't have time to address that today but will be able to have a look next week. |
The scale-info registry looks weird. The
|
That is expected because We should however still be able to uniquely identify the params and field usage because of the type parameter names. |
Ok makes sense then. I expected the registry to both uniquely identify + provide the concrete type. |
Just trying to understand this issue; is this ultimately something that needs fixing in |
AFAIU if scale-info must provide a unique identity to each generic types (I was assuming that) then it must be added to scale-info. Otherwise we need to somehow be able to track and distinguish generics in this library. |
I get the impression that scale-info will need a tweak to support that, and then we'll need a tweak in subxt to make use of the new information, basically. But somebody pelase correct me if wrong :) |
Description
(a). If a type has >1 generic, the >1 types are considered phantoms.
(b). More than considering them phantoms, ALL the fields using >1 generic in index are coerced back to the 0th one (i.e. with the below example,
a, b, c, d: T
. This is caused by (d).(c). This result in non-derived Encode/Decode for the given type.
(d). Worth to mention, the
TrackedSymbol
ids are all the same and it looks like they are comming fromTypeInfo
derive macro. Not sure this is a normal behavior either.I'm currently trying to fix the issue.
Reproducible snippet
Test case result
Logs from the test
The text was updated successfully, but these errors were encountered: