Skip to content

Commit

Permalink
Merge 7b02a50 into aedc983
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher authored Sep 17, 2024
2 parents aedc983 + 7b02a50 commit b365214
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ impl StatementKind {
// Semicolons are optional for these expressions
(ExpressionKind::Block(_), semi, _)
| (ExpressionKind::Unsafe(..), semi, _)
| (ExpressionKind::Interned(..), semi, _)
| (ExpressionKind::InternedStatement(..), semi, _)
| (ExpressionKind::If(_), semi, _) => {
if semi.is_some() {
StatementKind::Semi(expr)
Expand Down Expand Up @@ -865,7 +867,11 @@ impl Display for StatementKind {

impl Display for LetStatement {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "let {}: {} = {}", self.pattern, self.r#type, self.expression)
if matches!(&self.r#type.typ, UnresolvedTypeData::Unspecified) {
write!(f, "let {} = {}", self.pattern, self.expression)
} else {
write!(f, "let {}: {} = {}", self.pattern, self.r#type, self.expression)
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,11 +1621,11 @@ mod test {
#[test]
fn statement_recovery() {
let cases = vec![
Case { source: "let a = 4 + 3", expect: "let a: unspecified = (4 + 3)", errors: 0 },
Case { source: "let a = 4 + 3", expect: "let a = (4 + 3)", errors: 0 },
Case { source: "let a: = 4 + 3", expect: "let a: error = (4 + 3)", errors: 1 },
Case { source: "let = 4 + 3", expect: "let $error: unspecified = (4 + 3)", errors: 1 },
Case { source: "let = ", expect: "let $error: unspecified = Error", errors: 2 },
Case { source: "let", expect: "let $error: unspecified = Error", errors: 3 },
Case { source: "let = 4 + 3", expect: "let $error = (4 + 3)", errors: 1 },
Case { source: "let = ", expect: "let $error = Error", errors: 2 },
Case { source: "let", expect: "let $error = Error", errors: 3 },
Case { source: "foo = one two three", expect: "foo = one", errors: 1 },
Case { source: "constrain", expect: "constrain Error", errors: 2 },
Case { source: "assert", expect: "constrain Error", errors: 1 },
Expand Down Expand Up @@ -1659,7 +1659,7 @@ mod test {
},
Case {
source: "{ return 123; let foo = 4 + 3; }",
expect: concat!("{\n", " Error\n", " let foo: unspecified = (4 + 3)\n", "}"),
expect: concat!("{\n", " Error\n", " let foo = (4 + 3)\n", "}"),
errors: 1,
},
Case {
Expand Down Expand Up @@ -1709,7 +1709,7 @@ mod test {
expect: concat!(
"{\n",
" if ({\n",
" let foo: unspecified = (bar { baz: 42 })\n",
" let foo = (bar { baz: 42 })\n",
" (foo == (bar { baz: 42 }))\n",
" }) {\n",
" }\n",
Expand Down

0 comments on commit b365214

Please sign in to comment.