Skip to content

Commit

Permalink
chore: static_assert error message fix and split into is-dynamic an…
Browse files Browse the repository at this point in the history
…d is-false (noir-lang#5353)

# Description

Fix `static_assert` error message

## Problem\*

Error message for `static_assert` was ~"Argument to static_assert is
false or dynamic" at some point, but currently is copy/pasted from the
nested slices error

## Summary\*


## 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 Jun 28, 2024
1 parent 9c11fd2 commit f0b65c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub enum RuntimeError {
AssertConstantFailed { call_stack: CallStack },
#[error("The static_assert message is not constant")]
StaticAssertDynamicMessage { call_stack: CallStack },
#[error("Nested slices are not supported")]
#[error("Argument is dynamic")]
StaticAssertDynamicPredicate { call_stack: CallStack },
#[error("Argument is false")]
StaticAssertFailed { call_stack: CallStack },
#[error("Nested slices are not supported")]
NestedSlice { call_stack: CallStack },
Expand Down Expand Up @@ -124,8 +126,9 @@ impl RuntimeError {
| RuntimeError::UnInitialized { call_stack, .. }
| RuntimeError::UnknownLoopBound { call_stack }
| RuntimeError::AssertConstantFailed { call_stack }
| RuntimeError::StaticAssertFailed { call_stack }
| RuntimeError::StaticAssertDynamicMessage { call_stack }
| RuntimeError::StaticAssertDynamicPredicate { call_stack }
| RuntimeError::StaticAssertFailed { call_stack }
| RuntimeError::IntegerOutOfBounds { call_stack, .. }
| RuntimeError::UnsupportedIntegerSize { call_stack, .. }
| RuntimeError::NestedSlice { call_stack, .. }
Expand Down
6 changes: 5 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/assert_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ fn evaluate_static_assert(
Ok(false)
} else {
let call_stack = function.dfg.get_call_stack(instruction);
Err(RuntimeError::StaticAssertFailed { call_stack })
if function.dfg.is_constant(arguments[0]) {
Err(RuntimeError::StaticAssertFailed { call_stack })
} else {
Err(RuntimeError::StaticAssertDynamicPredicate { call_stack })
}
}
}

0 comments on commit f0b65c2

Please sign in to comment.