diff options
Diffstat (limited to 'compiler/GHC/Parser')
-rw-r--r-- | compiler/GHC/Parser/Errors.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Parser/Errors/Ppr.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Parser/PostProcess.hs | 9 |
3 files changed, 14 insertions, 1 deletions
diff --git a/compiler/GHC/Parser/Errors.hs b/compiler/GHC/Parser/Errors.hs index 83812f7673..e48f04aae5 100644 --- a/compiler/GHC/Parser/Errors.hs +++ b/compiler/GHC/Parser/Errors.hs @@ -90,6 +90,9 @@ data PsErrorDesc = PsErrLambdaCase -- ^ LambdaCase syntax used without the extension enabled + | PsErrEmptyLambda + -- ^ A lambda requires at least one parameter + | PsErrNumUnderscores !NumUnderscoreReason -- ^ Underscores in literals without the extension enabled diff --git a/compiler/GHC/Parser/Errors/Ppr.hs b/compiler/GHC/Parser/Errors/Ppr.hs index 7b9f2e64a0..0e83949a2e 100644 --- a/compiler/GHC/Parser/Errors/Ppr.hs +++ b/compiler/GHC/Parser/Errors/Ppr.hs @@ -141,6 +141,9 @@ pp_err = \case PsErrLambdaCase -> text "Illegal lambda-case (use LambdaCase)" + PsErrEmptyLambda + -> text "A lambda requires at least one parameter" + PsErrNumUnderscores reason -> text $ case reason of NumUnderscore_Integral -> "Use NumericUnderscores to allow underscores in integer literals" diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 1de9f0cd53..6411df34d9 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -1629,6 +1629,11 @@ instance DisambECP (HsCmd GhcPs) where cmdFail :: SrcSpan -> SDoc -> PV a cmdFail loc e = addFatalError $ PsError (PsErrParseErrorInCmd e) [] loc +checkLamMatchGroup :: SrcSpan -> MatchGroup GhcPs (LHsExpr GhcPs) -> PV () +checkLamMatchGroup l (MG { mg_alts = (L _ (matches:_))}) = do + when (null (hsLMatchPats matches)) $ addError $ PsError PsErrEmptyLambda [] l +checkLamMatchGroup _ _ = return () + instance DisambECP (HsExpr GhcPs) where type Body (HsExpr GhcPs) = HsExpr ecpFromCmd' (L l c) = do @@ -1640,7 +1645,9 @@ instance DisambECP (HsExpr GhcPs) where return $ mkRdrProjUpdate (noAnnSrcSpan l) fields arg isPun (EpAnn (spanAsAnchor l) anns cs) mkHsLamPV l mg = do cs <- getCommentsFor l - return $ L (noAnnSrcSpan l) (HsLam NoExtField (mg cs)) + let mg' = mg cs + checkLamMatchGroup l mg' + return $ L (noAnnSrcSpan l) (HsLam NoExtField mg') mkHsLetPV l bs c anns = do cs <- getCommentsFor l return $ L (noAnnSrcSpan l) (HsLet (EpAnn (spanAsAnchor l) anns cs) bs c) |