summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/main/DynFlags.hs2
-rw-r--r--compiler/rename/RnSource.hs25
-rw-r--r--compiler/typecheck/TcDerivUtils.hs2
3 files changed, 28 insertions, 1 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 02ad366338..7296809155 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -834,6 +834,7 @@ data WarningFlag =
| Opt_WarnStarBinder -- Since 8.6
| Opt_WarnImplicitKindVars -- Since 8.6
| Opt_WarnSpaceAfterBang
+ | Opt_WarnMissingDerivingStrategies -- Since 8.8
deriving (Eq, Show, Enum)
data Language = Haskell98 | Haskell2010
@@ -4022,6 +4023,7 @@ wWarningFlagsDeps = [
flagSpec "wrong-do-bind" Opt_WarnWrongDoBind,
flagSpec "missing-pattern-synonym-signatures"
Opt_WarnMissingPatternSynonymSignatures,
+ flagSpec "missing-deriving-strategies" Opt_WarnMissingDerivingStrategies,
flagSpec "simplifiable-class-constraints" Opt_WarnSimplifiableClassConstraints,
flagSpec "missing-home-modules" Opt_WarnMissingHomeModules,
flagSpec "unrecognised-warning-flags" Opt_WarnUnrecognisedWarningFlags,
diff --git a/compiler/rename/RnSource.hs b/compiler/rename/RnSource.hs
index c76eb31abc..e3e852984e 100644
--- a/compiler/rename/RnSource.hs
+++ b/compiler/rename/RnSource.hs
@@ -1009,6 +1009,7 @@ rnSrcDerivDecl (DerivDecl _ ty mds overlap)
<- rnLDerivStrategy DerivDeclCtx mds $ \strat_tvs ppr_via_ty ->
rnAndReportFloatingViaTvs strat_tvs loc ppr_via_ty "instance" $
rnHsSigWcType BindUnlessForall DerivDeclCtx ty
+ ; warnNoDerivStrat mds' loc
; return (DerivDecl noExt ty' mds' overlap, fvs) }
where
loc = getLoc $ hsib_body $ hswc_body ty
@@ -1710,6 +1711,29 @@ rnDataDefn doc (HsDataDefn { dd_ND = new_or_data, dd_cType = cType
; return (cL loc ds', fvs) }
rnDataDefn _ (XHsDataDefn _) = panic "rnDataDefn"
+warnNoDerivStrat :: Maybe (LDerivStrategy GhcRn)
+ -> SrcSpan
+ -> RnM ()
+warnNoDerivStrat mds loc
+ = do { dyn_flags <- getDynFlags
+ ; when (wopt Opt_WarnMissingDerivingStrategies dyn_flags) $
+ case mds of
+ Nothing -> addWarnAt
+ (Reason Opt_WarnMissingDerivingStrategies)
+ loc
+ (if xopt LangExt.DerivingStrategies dyn_flags
+ then no_strat_warning
+ else no_strat_warning $+$ deriv_strat_nenabled
+ )
+ _ -> pure ()
+ }
+ where
+ no_strat_warning :: SDoc
+ no_strat_warning = text "No deriving strategy specified. Did you want stock"
+ <> text ", newtype, or anyclass?"
+ deriv_strat_nenabled :: SDoc
+ deriv_strat_nenabled = text "Use DerivingStrategies to specify a strategy."
+
rnLHsDerivingClause :: HsDocContext -> LHsDerivingClause GhcPs
-> RnM (LHsDerivingClause GhcRn, FreeVars)
rnLHsDerivingClause doc
@@ -1720,6 +1744,7 @@ rnLHsDerivingClause doc
= do { (dcs', dct', fvs)
<- rnLDerivStrategy doc dcs $ \strat_tvs ppr_via_ty ->
mapFvRn (rn_deriv_ty strat_tvs ppr_via_ty) dct
+ ; warnNoDerivStrat dcs' loc
; pure ( cL loc (HsDerivingClause { deriv_clause_ext = noExt
, deriv_clause_strategy = dcs'
, deriv_clause_tys = cL loc' dct' })
diff --git a/compiler/typecheck/TcDerivUtils.hs b/compiler/typecheck/TcDerivUtils.hs
index 86205de5fd..5f48e5f003 100644
--- a/compiler/typecheck/TcDerivUtils.hs
+++ b/compiler/typecheck/TcDerivUtils.hs
@@ -62,7 +62,7 @@ import ListSetOps (assocMaybe)
-- is a simple reader around 'TcRn'.
type DerivM = ReaderT DerivEnv TcRn
--- | Is GHC processing a stanalone deriving declaration?
+-- | Is GHC processing a standalone deriving declaration?
isStandaloneDeriv :: DerivM Bool
isStandaloneDeriv = asks (go . denv_ctxt)
where