Skip to content

Mutators with type parameters need to pass type parameters to inner call when associated type is used #157

@azriel91

Description

@azriel91

Heya, I came across this use case:

trait HasS {
    type MyS: Default + AddAssign;
}

struct HasSImpl;

impl HasS for HasSImpl {
    type MyS = u32;
}

#[derive(Debug, PartialEq, TypedBuilder)]
struct Foo<S: Default + AddAssign> {
    #[builder(via_mutators, mutators(
        fn x_plus<H>(self, s: <H as HasS>::MyS)
        // ^^^^^^ cannot infer type of the type parameter `H` declared on the method `x_plus`
        where H: HasS<MyS = S> {
            self.x += s;
        }
    ))]
    x: S,
}

The issue in the generated code:

impl<S: Default + AddAssign> FooBuilder<S, ((S,),)> {
    // ..
    fn x_plus<H>(self, s: <H as HasS>::MyS) -> FooBuilder<S, ((S,),)>
    where
        H: HasS<MyS = S>,
    {
        // ..

        {
            let (s) = __args;
            __mutator.x_plus::<H>(s);
            //              ^^^^^
            //              this was missing
        }

        //..
    }
}

I've got a PR incoming to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions