Skip to content
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

CtString::append_str docs say that appending to &mut self prevents method from being found #6980

Open
michaeljklein opened this issue Jan 7, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

// Bug: using &mut self as the object results in this method not being found

impl CtString {
    // Bug: using &mut self as the object results in this method not being found
    // docs:start:append_str
    pub comptime fn append_str<let N: u32>(self, s: str<N>) -> Self {
        // docs:end:append_str
        f"{self}{s}".as_ctstring()
    }

Expected Behavior

Fix bug or else add regression test and update comment

Bug

using &mut self as the object results in this method not being found

To Reproduce

Workaround

Yes

Workaround Description

Make a copy of the CtString

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added the bug Something isn't working label Jan 7, 2025
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jan 7, 2025
@asterite
Copy link
Collaborator

asterite commented Jan 8, 2025

I think in a recent PR that merged I fixed that:

// Handle auto-dereferencing `&mut T` into `T`
if let Type::MutableReference(object) = object {
if object.unify(typ).is_ok() {
return true;
}
}

That said, I'm not sure what's the fix here. We could change it to &mut self but self doesn't seem to mutate here 🤔

@jfecher
Copy link
Contributor

jfecher commented Jan 8, 2025

The original method was written with signature fn(Self, str<N>) -> Self instead of fn(&mut Self, str<N>) to avoid passing a &mut self. So if that's fixed we can change the method to the original signature, although it'd be a breaking change now.

@michaeljklein
Copy link
Contributor Author

@jfecher in that case, would it be useful to have a second method append_str_mut or similar?

Otherwise, I see a test for auto-dereferencing &mut T into T here.

@jfecher
Copy link
Contributor

jfecher commented Jan 8, 2025

I think I'd rather make the breaking change or keep the current function than have 2 functions in the stdlib which more or less do the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants