diff --git a/flang/lib/Parser/executable-parsers.cpp b/flang/lib/Parser/executable-parsers.cpp index fc67d11a7ed75..92e7d25d93d3b 100644 --- a/flang/lib/Parser/executable-parsers.cpp +++ b/flang/lib/Parser/executable-parsers.cpp @@ -305,7 +305,8 @@ TYPE_CONTEXT_PARSER( TYPE_CONTEXT_PARSER("IF construct"_en_US, construct( statement(construct(maybe(name / ":"), - "IF" >> parenthesized(scalarLogicalExpr) / "THEN")), + "IF" >> parenthesized(scalarLogicalExpr) / + recovery("THEN"_tok, lookAhead(endOfStmt)))), block, many(construct( unambiguousStatement(construct( diff --git a/flang/test/Parser/missing-then.f90 b/flang/test/Parser/missing-then.f90 new file mode 100644 index 0000000000000..ccaee3e801236 --- /dev/null +++ b/flang/test/Parser/missing-then.f90 @@ -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