Commit 21c5c9c0 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com

Move the standalone-deriving flag test from parser to renamer

This is just a tiny refactoring.  In general, we're trying to
get rid of parser errors in favour of later, more civlised, errors.
parent 431453c0
......@@ -707,7 +707,7 @@ tycl_hdr :: { Located (LHsContext RdrName, LHsType RdrName) }
-- Glasgow extension: stand-alone deriving declarations
stand_alone_deriving :: { LDerivDecl RdrName }
: 'deriving' 'instance' inst_type {% checkDerivDecl (LL (DerivDecl $3)) }
: 'deriving' 'instance' inst_type { LL (DerivDecl $3) }
-----------------------------------------------------------------------------
-- Nested declarations
......
......@@ -38,7 +38,6 @@ module RdrHsSyn (
checkTyVars, -- [LHsType RdrName] -> P ()
checkKindSigs, -- [LTyClDecl RdrName] -> P ()
checkInstType, -- HsType -> P HsType
checkDerivDecl, -- LDerivDecl RdrName -> P (LDerivDecl RdrName)
checkPattern, -- HsExp -> P HsPat
bang_RDR,
checkPatterns, -- SrcLoc -> [HsExp] -> P [HsPat]
......@@ -658,15 +657,6 @@ checkPred (L spn ty)
check loc _ _ = parseError loc
"malformed class assertion"
---------------------------------------------------------------------------
-- Checking stand-alone deriving declarations
checkDerivDecl :: LDerivDecl RdrName -> P (LDerivDecl RdrName)
checkDerivDecl d@(L loc _) =
do stDerivOn <- extension standaloneDerivingEnabled
if stDerivOn then return d
else parseError loc "Illegal stand-alone deriving declaration (use -XStandaloneDeriving)"
---------------------------------------------------------------------------
-- Checking statements in a do-expression
-- We parse do { e1 ; e2 ; }
......
......@@ -499,9 +499,16 @@ extendTyVarEnvForMethodBinds tyvars thing_inside
\begin{code}
rnSrcDerivDecl :: DerivDecl RdrName -> RnM (DerivDecl Name, FreeVars)
rnSrcDerivDecl (DerivDecl ty)
= do ty' <- rnLHsType (text "a deriving decl") ty
let fvs = extractHsTyNames ty'
return (DerivDecl ty', fvs)
= do { standalone_deriv_ok <- doptM Opt_StandaloneDeriving
; unless standalone_deriv_ok (addErr standaloneDerivErr)
; ty' <- rnLHsType (text "a deriving decl") ty
; let fvs = extractHsTyNames ty'
; return (DerivDecl ty', fvs) }
standaloneDerivErr :: SDoc
standaloneDerivErr
= hang (ptext (sLit "Illegal standalone deriving declaration"))
2 (ptext (sLit "Use -XStandaloneDeriving to enable this extension"))
\end{code}
%*********************************************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment