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

Multi-line where clauses fail to parse with low-level error #4809

Closed
michaeljklein opened this issue Apr 15, 2024 · 1 comment · Fixed by #5594
Closed

Multi-line where clauses fail to parse with low-level error #4809

michaeljklein opened this issue Apr 15, 2024 · 1 comment · Fixed by #5594
Assignees
Labels
bug Something isn't working parser issues primarily related to the parser

Comments

@michaeljklein
Copy link
Contributor

Aim

Attempted to separate where clause to multiple lines as is commonly found in Rust

Expected Behavior

It to either fail with an informative error or be accepted as equivalent to a single-line where clause, i.e. impl<A, B> Default for Foo<A, B> where A: Default, B: Default

Bug

Compiling the following:

struct Foo<A, B> { }

impl<A, B> Default for Foo<A, B>
where
    A: Default,
    B: Default,
{
    fn default() -> Self { Foo { } }
}

fails with:

error: Unexpected {, expected one of bool, comptime, crate, dep, Field, fn, fmtstr, impl, str, &, (, [, integer type, Ident
   ┌─ /Users/michaelklein/Coding/rust/noir/test_programs/compile_success_empty/name_shadowing_template/binary/src/local_module.nr:19:1
   │
19 │ {
   │ -
   │

To Reproduce

  1. nargo compile the test program as main.nr

Project Impact

Nice-to-have

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

None

Nargo Version

No response

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added bug Something isn't working parser issues primarily related to the parser labels Apr 15, 2024
@jfecher
Copy link
Contributor

jfecher commented Apr 16, 2024

The error here is a result of the ending comma, removing it results in no errors:

struct Foo<A, B> { }

impl<A, B> Default for Foo<A, B>
where
    A: Default,
    B: Default
{
    fn default() -> Self { Foo { } }
}

The where_clause parser in the parser looks like it is missing an .allow_trailing() call.

@asterite asterite self-assigned this Jul 23, 2024
github-merge-queue bot pushed a commit that referenced this issue Jul 23, 2024
# Description

## Problem

Resolves #4809

## Summary

Also removes some duplicated parsing functions (I checked and their code
was exactly the same).

## Additional Context

None.

## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser issues primarily related to the parser
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants