Skip to content

Commit

Permalink
[Parser] test failure on parsing nested blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
isuckatcs committed Jul 5, 2024
1 parent 9182b2b commit 7ca7814
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,11 @@ std::unique_ptr<IfStmt> TheParser::parseIfStmt() {
return error(nextToken.location, "expected 'else' body");

falseBlock = parseBlock();
if (!falseBlock)
return nullptr;
}

if (!falseBlock)
return nullptr;

return std::make_unique<IfStmt>(location, std::move(condition),
std::move(trueBranch), std::move(falseBlock));
}
Expand Down
6 changes: 6 additions & 0 deletions test/parser/error_parsing_else_block.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: compiler %s -ast-dump 2>&1 | filecheck %s
fn main(): void {
if 0.0 {}
else {
// CHECK: [[# @LINE + 2 ]]:1: error: expected '}' at the end of a block
// CHECK: [[# @LINE + 1 ]]:1: error: expected '}' at the end of a block
5 changes: 5 additions & 0 deletions test/parser/error_parsing_if_block.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: compiler %s -ast-dump 2>&1 | filecheck %s
fn main(): void {
if 0.0 {
// CHECK: [[# @LINE + 2 ]]:1: error: expected '}' at the end of a block
// CHECK: [[# @LINE + 1 ]]:1: error: expected '}' at the end of a block
5 changes: 5 additions & 0 deletions test/parser/error_parsing_while_block.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: compiler %s -ast-dump 2>&1 | filecheck %s
fn main(): void {
while 0.0 {
// CHECK: [[# @LINE + 2 ]]:1: error: expected '}' at the end of a block
// CHECK: [[# @LINE + 1 ]]:1: error: expected '}' at the end of a block

0 comments on commit 7ca7814

Please sign in to comment.