Skip to content

[Bugfix] Invalid generation of types with >1 generic parameters#1023

Merged
tadeohepperle merged 3 commits into
masterfrom
tadeo-hepperle-invalid-generation-types-multiple-generic-parameters
Jun 23, 2023
Merged

[Bugfix] Invalid generation of types with >1 generic parameters#1023
tadeohepperle merged 3 commits into
masterfrom
tadeo-hepperle-invalid-generation-types-multiple-generic-parameters

Conversation

@tadeohepperle

@tadeohepperle tadeohepperle commented Jun 20, 2023

Copy link
Copy Markdown
Contributor

fixes #550

Investigated reason for the bug: In subxt, when calling resolve_field_type_path() to get the type of a generic, we were not taking into account multiple generics with different names (originial_name e.g. T, U, V, ...). The function just looked for the first type where the type (e.g. u8) matches (see: parent_type_params.iter().find(...)).

Fix: add an optional parameter original_name: Option<&str> to the type resolving function to also check the name of the generic argument.

Added a test to confirm the behavior is now as desired. The test matches the problem statement in #550.

@tadeohepperle tadeohepperle changed the title add original name match [Bugfix] Invalid generation of types with >1 generic parameters Jun 21, 2023
@tadeohepperle tadeohepperle marked this pull request as ready for review June 21, 2023 11:19
@tadeohepperle tadeohepperle requested a review from a team June 21, 2023 11:19
@tadeohepperle tadeohepperle self-assigned this Jun 21, 2023

@jsdw jsdw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! Also love the test :)

}

#[test]
fn more_than_1_generic_parameters_work() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@lexnv lexnv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Amazing PR!

use scale_info::{meta_type, IntoPortable, TypeInfo};
use scale_info::{meta_type, IntoPortable, PortableRegistry, Registry, TypeInfo};
use subxt_codegen::{CratePath, DerivesRegistry, RuntimeGenerator, TypeSubstitutes};
use syn::__private::quote;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm, does that compile? :)

It would be better to bring in quote in dependency tree as this might break between releases...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could do that, good idea.

@tadeohepperle tadeohepperle merged commit 8413c4d into master Jun 23, 2023
@tadeohepperle tadeohepperle deleted the tadeo-hepperle-invalid-generation-types-multiple-generic-parameters branch June 23, 2023 13:14
tadeohepperle added a commit that referenced this pull request Jul 4, 2023
* add original name match

* add unit test for generic params
@jsdw jsdw mentioned this pull request Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid generation of types with >1 generic

4 participants