on master help sign in
Enable some non-conflicting language extensions by default
01486edmrkkrp
data/examples/declaration/value/function/list-comprehensions.hs+1−1
@@ -1,4 +1,4 @@
1−foo x = [a|a<-x]
1+foo x = [a |a<-x]
2
2
3bar x y = [ (a, b) | a<-x, even a , b<-y, a != b ]
3bar x y = [ (a, b) | a<-x, even a , b<-y, a != b ]
4
4
src/Ormolu/Parser.hs+70−3
@@ -10,10 +10,10 @@ where
10import Control.Exception
10import Control.Exception
11import Control.Monad
11import Control.Monad
12import Control.Monad.IO.Class
12import Control.Monad.IO.Class
13−import Data.List (isPrefixOf)
13+import Data.List (isPrefixOf, foldl')
14import Data.Maybe (catMaybes)
14import Data.Maybe (catMaybes)
15import GHC hiding (IE, parseModule, parser)
15import GHC hiding (IE, parseModule, parser)
16−import GHC.LanguageExtensions.Type (Extension (Cpp))
16+import GHC.LanguageExtensions.Type (Extension (..))
17import GHC.Paths (libdir)
17import GHC.Paths (libdir)
18import Ormolu.Config
18import Ormolu.Config
19import Ormolu.Exception
19import Ormolu.Exception
@@ -87,7 +87,7 @@ initDynFlagsPure fp input = do
87 -- I was told we could get away with using the 'unsafeGlobalDynFlags'. as
87 -- I was told we could get away with using the 'unsafeGlobalDynFlags'. as
88 -- long as 'parseDynamicFilePragma' is impure there seems to be no reason
88 -- long as 'parseDynamicFilePragma' is impure there seems to be no reason
89 -- to use it.
89 -- to use it.
90− dflags0 <- GHC.getSessionDynFlags
90+ dflags0 <- setDefaultExts <$> GHC.getSessionDynFlags
91 let tokens = GHC.getOptions dflags0 (GHC.stringToStringBuffer input) fp
91 let tokens = GHC.getOptions dflags0 (GHC.stringToStringBuffer input) fp
92 (dflags1, _, _) <- GHC.parseDynamicFilePragma dflags0 tokens
92 (dflags1, _, _) <- GHC.parseDynamicFilePragma dflags0 tokens
93 -- Turn this on last to avoid T10942
93 -- Turn this on last to avoid T10942
@@ -154,3 +154,70 @@ getPragma s@(x:xs)
154 | otherwise =
154 | otherwise =
155 let (prag, remline) = getPragma xs
155 let (prag, remline) = getPragma xs
156 in (x:prag, ' ':remline)
156 in (x:prag, ' ':remline)
157+
158+-- | Enable all language extensions that we think should be enabled by
159+-- default for ease of use.
160+
161+setDefaultExts :: DynFlags -> DynFlags
162+setDefaultExts flags = foldl' GHC.xopt_set flags
163+ [ OverlappingInstances
164+ , UndecidableInstances
165+ , IncoherentInstances
166+ , UndecidableSuperClasses
167+ , ExtendedDefaultRules
168+ , ForeignFunctionInterface
169+ , TemplateHaskell
170+ , QuasiQuotes
171+ , ImplicitParams
172+ , ScopedTypeVariables
173+ , BangPatterns
174+ , TypeFamilies
175+ , TypeFamilyDependencies
176+ , TypeInType
177+ , OverloadedStrings
178+ , OverloadedLists
179+ , RecordWildCards
180+ , RecordPuns
181+ , GADTs
182+ , GADTSyntax
183+ , NPlusKPatterns
184+ , ConstraintKinds
185+ , PolyKinds
186+ , DataKinds
187+ , InstanceSigs
188+ , StandaloneDeriving
189+ , DefaultSignatures
190+ , DeriveAnyClass
191+ , DerivingStrategies
192+ , DerivingVia
193+ , FlexibleContexts
194+ , FlexibleInstances
195+ , MultiParamTypeClasses
196+ , FunctionalDependencies
197+ , ExistentialQuantification
198+ , EmptyDataDecls
199+ , KindSignatures
200+ , RoleAnnotations
201+ , GeneralizedNewtypeDeriving
202+ , RecursiveDo
203+ , TupleSections
204+ , PatternGuards
205+ , RankNTypes
206+ , TypeOperators
207+ , ExplicitNamespaces
208+ , PackageImports
209+ , ExplicitForAll
210+ , LambdaCase
211+ , MultiWayIf
212+ , BinaryLiterals
213+ , NegativeLiterals
214+ , HexFloatLiterals
215+ , OverloadedLabels
216+ , EmptyCase
217+ , NamedWildCards
218+ , StaticPointers
219+ , TypeApplications
220+ , NumericUnderscores
221+ , QuantifiedConstraints
222+ , StarIsType
223+ ]