diff options
Diffstat (limited to 'compiler/GHC/Parser')
-rw-r--r-- | compiler/GHC/Parser/Errors/Ppr.hs | 8 | ||||
-rw-r--r-- | compiler/GHC/Parser/Errors/Types.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Parser/PostProcess.hs | 27 |
3 files changed, 27 insertions, 11 deletions
diff --git a/compiler/GHC/Parser/Errors/Ppr.hs b/compiler/GHC/Parser/Errors/Ppr.hs index 6a2152f3f7..6b08ae0877 100644 --- a/compiler/GHC/Parser/Errors/Ppr.hs +++ b/compiler/GHC/Parser/Errors/Ppr.hs @@ -520,6 +520,12 @@ instance Diagnostic PsMessage where text "character in package name" ] + PsErrIllegalGadtRecordMultiplicity arr + -> mkSimpleDecorated $ vcat + [ text "Parse error" <> colon <+> quotes (ppr arr) + , text "Record constructors in GADTs must use an ordinary, non-linear arrow." + ] + diagnosticReason = \case PsUnknownMessage m -> diagnosticReason m PsWarnTab{} -> WarningWithFlag Opt_WarnTabs @@ -628,6 +634,7 @@ instance Diagnostic PsMessage where PsErrUnexpectedTypeInDecl{} -> ErrorWithoutFlag PsErrInvalidPackageName{} -> ErrorWithoutFlag PsErrParseRightOpSectionInPat{} -> ErrorWithoutFlag + PsErrIllegalGadtRecordMultiplicity{} -> ErrorWithoutFlag diagnosticHints = \case PsUnknownMessage m -> diagnosticHints m @@ -754,6 +761,7 @@ instance Diagnostic PsMessage where PsErrInvalidTypeSignature{} -> noHints PsErrUnexpectedTypeInDecl{} -> noHints PsErrInvalidPackageName{} -> noHints + PsErrIllegalGadtRecordMultiplicity{} -> noHints suggestParensAndBlockArgs :: [GhcHint] suggestParensAndBlockArgs = diff --git a/compiler/GHC/Parser/Errors/Types.hs b/compiler/GHC/Parser/Errors/Types.hs index d75c223253..38c54b7149 100644 --- a/compiler/GHC/Parser/Errors/Types.hs +++ b/compiler/GHC/Parser/Errors/Types.hs @@ -395,6 +395,9 @@ data PsMessage -- TODO: embed the proper operator, if possible | forall infixOcc. (OutputableBndr infixOcc) => PsErrParseRightOpSectionInPat !infixOcc !(PatBuilder GhcPs) + -- | Illegal linear arrow or multiplicity annotation in GADT record syntax + | PsErrIllegalGadtRecordMultiplicity !(HsArrow GhcPs) + newtype StarIsType = StarIsType Bool -- | Extra details about a parse error, which helps diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 34c973fefc..ffe44227fd 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -716,17 +716,22 @@ mkGadtDecl loc names ty annsIn = do cs <- getCommentsFor loc let l = noAnnSrcSpan loc - let (args, res_ty, annsa, csa) - | L ll (HsFunTy af _w (L loc' (HsRecTy an rf)) res_ty) <- body_ty - = let - an' = addTrailingAnnToL (locA loc') (anns af) (comments af) an - in ( RecConGADT (L (SrcSpanAnn an' (locA loc')) rf), res_ty - , [], epAnnComments (ann ll)) - | otherwise - = let (anns, cs, arg_types, res_type) = splitHsFunType body_ty - in (PrefixConGADT arg_types, res_type, anns, cs) - - an = case outer_bndrs of + (args, res_ty, annsa, csa) <- + case body_ty of + L ll (HsFunTy af hsArr (L loc' (HsRecTy an rf)) res_ty) -> do + let an' = addTrailingAnnToL (locA loc') (anns af) (comments af) an + case hsArr of + HsUnrestrictedArrow _ -> return () + _ -> addError $ mkPlainErrorMsgEnvelope (getLocA body_ty) $ + (PsErrIllegalGadtRecordMultiplicity hsArr) + + return ( RecConGADT (L (SrcSpanAnn an' (locA loc')) rf), res_ty + , [], epAnnComments (ann ll)) + _ -> do + let (anns, cs, arg_types, res_type) = splitHsFunType body_ty + return (PrefixConGADT arg_types, res_type, anns, cs) + + let an = case outer_bndrs of _ -> EpAnn (spanAsAnchor loc) (annsIn ++ annsa) (cs Semi.<> csa) pure $ L l ConDeclGADT |