Skip to content

nightly-2024-01-26: fix: Better errors for missing `fn` keyword (#4154)

Pre-release
Pre-release
Compare
Choose a tag to compare
@github-actions github-actions released this 26 Jan 02:12
· 1637 commits to master since this release
057c208
# Description

Using `force(just(Token::EOF))` to ensure the whole file is parsed
appears to hide the module error.

## Problem\*

Resolves https://github.com/noir-lang/noir/issues/3768

## Summary\*

Before:

```bash
❯ cargo run build
error: Parser: expected an end of input but found #[aztec(private)]
  ┌─ /Users/michaelklein/Coding/rust/noir/test_programs/compile_failure/no_fn_keyword/src/main.nr:1:1
  │
1 │ #[aztec(private)]
  │ -----------------
  │

Aborting due to 1 previous error
```

After:

```bash
error: Unexpected main, expected one of fn, internal, open, pub, struct, unconstrained, Attribute
  ┌─ /Users/michaelklein/Coding/rust/noir/test_programs/compile_failure/no_fn_keyword/src/main.nr:2:1
  │
2 │ main() {
  │ ----
  │

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.

---------

Co-authored-by: jfecher <[email protected]>