Skip to content

Commit

Permalink
[flang] Better error recovery for missing THEN in IF construct
Browse files Browse the repository at this point in the history
Presented with "IF (...)" with no following tokens in the statement,
diagnose a missing "THEN" instead of complaining about all of the
possible action statement initial tokens that could have been there
for a non-construct IF statement.

Fixes #62299.

Differential Revision: https://reviews.llvm.org/D150783
  • Loading branch information
klausler committed May 18, 2023
1 parent d624aba commit 60b6730
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flang/lib/Parser/executable-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ TYPE_CONTEXT_PARSER(
TYPE_CONTEXT_PARSER("IF construct"_en_US,
construct<IfConstruct>(
statement(construct<IfThenStmt>(maybe(name / ":"),
"IF" >> parenthesized(scalarLogicalExpr) / "THEN")),
"IF" >> parenthesized(scalarLogicalExpr) /
recovery("THEN"_tok, lookAhead(endOfStmt)))),
block,
many(construct<IfConstruct::ElseIfBlock>(
unambiguousStatement(construct<ElseIfStmt>(
Expand Down
8 changes: 8 additions & 0 deletions flang/test/Parser/missing-then.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
! RUN: not %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
!CHECK: expected 'THEN'
!CHECK-NOT: expected 'PAUSE'
if (.TRUE.)
!CHECK: expected 'THEN'
else if (.FALSE.)
end if
end

0 comments on commit 60b6730

Please sign in to comment.