Skip to content

Commit

Permalink
chore: parse fieldless structures (#3021)
Browse files Browse the repository at this point in the history
Co-authored-by: kevaundray <kevtheappdev@gmail.com>
  • Loading branch information
kek kek kek and kevaundray authored Oct 9, 2023
1 parent bb712fd commit b71b15d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,15 @@ fn struct_definition() -> impl NoirParser<TopLevelStatement> {
use self::Keyword::Struct;
use Token::*;

let fields = struct_fields().delimited_by(just(LeftBrace), just(RightBrace)).recover_with(
nested_delimiters(
let fields = struct_fields()
.delimited_by(just(LeftBrace), just(RightBrace))
.recover_with(nested_delimiters(
LeftBrace,
RightBrace,
[(LeftParen, RightParen), (LeftBracket, RightBracket)],
|_| vec![],
),
);
))
.or(just(Semicolon).map(|_| Vec::new()));

attributes()
.or_not()
Expand Down Expand Up @@ -2281,6 +2282,7 @@ mod test {
#[test]
fn parse_structs() {
let cases = vec![
"struct Foo;",
"struct Foo { }",
"struct Bar { ident: Field, }",
"struct Baz { ident: Field, other: Field }",
Expand Down Expand Up @@ -2315,12 +2317,13 @@ mod test {
#[test]
fn parse_constructor() {
let cases = vec![
"Baz",
"Bar { ident: 32 }",
"Baz { other: 2 + 42, ident: foo() + 1 }",
"Baz { other, ident: foo() + 1, foo }",
];
parse_all(expression(), cases);

parse_all(expression(), cases);
parse_with(expression(), "Foo { a + b }").unwrap_err();
}

Expand Down
4 changes: 4 additions & 0 deletions tooling/nargo_cli/tests/execution_success/struct/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ fn get_dog() -> Animal {
dog
}

struct Unit;

fn main(x: Field, y: Field) {
let unit = Unit {};

let first = Foo::default(x,y);
let p = Pair { first, second: 1 };

Expand Down

0 comments on commit b71b15d

Please sign in to comment.