Skip to content

Commit

Permalink
chore: make nested slice error more clear for [[T]; N] case (#5906)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

The `NestedSlice` error is unclear when there is only one slice:

```bash
error: Nested slices are not supported
   ┌─ /Users/michaelklein/Coding/noir/two_tag/src/main.nr:31:12
   │
31 │     rules: [[Field]; N],
   │            ------------ Try to use a constant sized array instead
```

## Summary\*

Rephrases the `NestedSlice` error message to make it more clear that
slices within arrays or other slices are disallowed.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** 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.
  • Loading branch information
michaeljklein authored Sep 3, 2024
1 parent 6f30e42 commit 712468a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum RuntimeError {
StaticAssertDynamicPredicate { call_stack: CallStack },
#[error("Argument is false")]
StaticAssertFailed { call_stack: CallStack },
#[error("Nested slices are not supported")]
#[error("Nested slices, i.e. slices within an array or slice, are not supported")]
NestedSlice { call_stack: CallStack },
#[error("Big Integer modulus do no match")]
BigIntModulus { call_stack: CallStack },
Expand Down
6 changes: 3 additions & 3 deletions compiler/noirc_frontend/src/hir/resolution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub enum ResolverError {
NumericConstantInFormatString { name: String, span: Span },
#[error("Closure environment must be a tuple or unit type")]
InvalidClosureEnvironment { typ: Type, span: Span },
#[error("Nested slices are not supported")]
#[error("Nested slices, i.e. slices within an array or slice, are not supported")]
NestedSlices { span: Span },
#[error("#[recursive] attribute is only allowed on entry points to a program")]
MisplacedRecursiveAttribute { ident: Ident },
Expand Down Expand Up @@ -323,8 +323,8 @@ impl<'a> From<&'a ResolverError> for Diagnostic {
format!("{typ} is not a valid closure environment type"),
"Closure environment must be a tuple or unit type".to_string(), *span),
ResolverError::NestedSlices { span } => Diagnostic::simple_error(
"Nested slices are not supported".into(),
"Try to use a constant sized array instead".into(),
"Nested slices, i.e. slices within an array or slice, are not supported".into(),
"Try to use a constant sized array or BoundedVec instead".into(),
*span,
),
ResolverError::MisplacedRecursiveAttribute { ident } => {
Expand Down

0 comments on commit 712468a

Please sign in to comment.