[flang] fix flang-compiler/f18#303, better error recovery for misplaced type paramete...
authorpeter klausler <pklausler@nvidia.com>
Thu, 28 Feb 2019 01:03:40 +0000 (17:03 -0800)
committerpeter klausler <pklausler@nvidia.com>
Thu, 28 Feb 2019 17:31:16 +0000 (09:31 -0800)
Original-commit: flang-compiler/f18@ebaa23cbcd91ba83b65b8dd174baffab1395bc65
Reviewed-on: https://github.com/flang-compiler/f18/pull/307

flang/lib/parser/grammar.h
flang/lib/parser/parse-tree.h

index 79e4365..6d99f4a 100644 (file)
@@ -745,9 +745,9 @@ TYPE_PARSER(construct<SequenceStmt>("SEQUENCE"_tok))
 // R732 type-param-def-stmt ->
 //        integer-type-spec , type-param-attr-spec :: type-param-decl-list
 // R734 type-param-attr-spec -> KIND | LEN
-TYPE_PARSER(construct<TypeParamDefStmt>(integerTypeSpec / ",",
-    "KIND" >> pure(common::TypeParamAttr::Kind) ||
-        "LEN" >> pure(common::TypeParamAttr::Len),
+constexpr auto kindOrLen{"KIND" >> pure(common::TypeParamAttr::Kind) ||
+    "LEN" >> pure(common::TypeParamAttr::Len)};
+TYPE_PARSER(construct<TypeParamDefStmt>(integerTypeSpec / ",", kindOrLen,
     "::" >> nonemptyList("expected type parameter declarations"_err_en_US,
                 Parser<TypeParamDecl>{})))
 
@@ -784,7 +784,11 @@ TYPE_PARSER(construct<ComponentAttrSpec>(accessSpec) ||
     construct<ComponentAttrSpec>("CODIMENSION" >> coarraySpec) ||
     construct<ComponentAttrSpec>(contiguous) ||
     construct<ComponentAttrSpec>("DIMENSION" >> Parser<ComponentArraySpec>{}) ||
-    construct<ComponentAttrSpec>(pointer))
+    construct<ComponentAttrSpec>(pointer) ||
+    construct<ComponentAttrSpec>(recovery(
+        fail<ErrorRecovery>(
+            "type parameter definitions must appear before component declarations"_err_en_US),
+        kindOrLen >> construct<ErrorRecovery>())))
 
 // R739 component-decl ->
 //        component-name [( component-array-spec )]
index 3f2020e..eabc7bb 100644 (file)
@@ -954,7 +954,7 @@ EMPTY_CLASS(Contiguous);
 struct ComponentAttrSpec {
   UNION_CLASS_BOILERPLATE(ComponentAttrSpec);
   std::variant<AccessSpec, Allocatable, CoarraySpec, Contiguous,
-      ComponentArraySpec, Pointer>
+      ComponentArraySpec, Pointer, ErrorRecovery>
       u;
 };