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

Confusing error message when trying to mutate a string #4267

Closed
ggiraldez opened this issue Feb 5, 2024 · 0 comments · Fixed by #4611
Closed

Confusing error message when trying to mutate a string #4267

ggiraldez opened this issue Feb 5, 2024 · 0 comments · Fixed by #4611
Labels
bug Something isn't working

Comments

@ggiraldez
Copy link
Contributor

ggiraldez commented Feb 5, 2024

Aim

Given this test program:

fn main() {
    let mut s = "hello";
    s[0] = 64;
}

Expected Behavior

Either a successful compilation, or an error message saying that string cannot be mutated.

Bug

The compiler produces the following confusing error message instead:

error: Expected type array, found type str<5>
  ┌─ /home/ggiraldez/Scratchpad/mutable_str/src/main.nr:3:12
  │
3 │     s[0] = 64;
  │            --
  │

Aborting due to 1 previous error

It seems the compiler expects s to be of type array, but the error location is located on the RHS of the assignment.

To Reproduce

Compile the above program with nargo compile.

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@ggiraldez ggiraldez added the bug Something isn't working label Feb 5, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Feb 5, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 21, 2024
# Description

## Problem\*

Resolves #4267

## Summary\*

New error:

```bash
error: Strings do not support indexed assignment
  ┌─ /Users/michaelklein/Coding/rust/noir/test_programs/compile_failure/mutable_str_index/src/main.nr:3:5
  │
3 │     example[0] = "?";
  │     -------
  │

Aborting due to 1 previous error
```

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Mar 21, 2024
TomAFrench pushed a commit that referenced this issue Apr 3, 2024
# Description

## Problem\*

Resolves #4267

## Summary\*

New error:

```bash
error: Strings do not support indexed assignment
  ┌─ /Users/michaelklein/Coding/rust/noir/test_programs/compile_failure/mutable_str_index/src/main.nr:3:5
  │
3 │     example[0] = "?";
  │     -------
  │

Aborting due to 1 previous error
```

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
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
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant