Skip to content

Commit a445fba

Browse files
committed
Use CPP to avoid errors with old GHC from TypeApplications in class instance
1 parent 52f76ea commit a445fba

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

servant-server/src/Servant/Server/Internal.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE AllowAmbiguousTypes #-}
22
{-# LANGUAGE ConstraintKinds #-}
3+
{-# LANGUAGE CPP #-}
34
{-# LANGUAGE DataKinds #-}
45
{-# LANGUAGE DeriveDataTypeable #-}
56
{-# LANGUAGE FlexibleContexts #-}
@@ -823,7 +824,11 @@ instance (HasContextEntry context (NamedContext name subContext), HasServer subA
823824
-------------------------------------------------------------------------------
824825

825826
-- Erroring instance for 'HasServer' when a combinator is not fully applied
826-
instance TypeError (PartialApplication @(Type -> [Type] -> Constraint) HasServer arr) => HasServer ((arr :: a -> b) :> sub) context
827+
instance TypeError (PartialApplication
828+
#if __GLASGOW_HASKELL__ >= 904
829+
@(Type -> [Type] -> Constraint)
830+
#endif
831+
HasServer arr) => HasServer ((arr :: a -> b) :> sub) context
827832
where
828833
type ServerT (arr :> sub) _ = TypeError (PartialApplication (HasServer :: * -> [*] -> Constraint) arr)
829834
route = error "unreachable"
@@ -867,7 +872,11 @@ type HasServerArrowTypeError a b =
867872
-- XXX: This omits the @context@ parameter, e.g.:
868873
--
869874
-- "There is no instance for HasServer (Bool :> …)". Do we care ?
870-
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceForSub @(Type -> [Type] -> Constraint) HasServer ty) => HasServer (ty :> sub) context
875+
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceForSub
876+
#if __GLASGOW_HASKELL__ >= 904
877+
@(Type -> [Type] -> Constraint)
878+
#endif
879+
HasServer ty) => HasServer (ty :> sub) context
871880

872881
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceFor (HasServer api context)) => HasServer api context
873882

servant/src/Servant/Links.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE AllowAmbiguousTypes #-}
22
{-# LANGUAGE ConstraintKinds #-}
3+
{-# LANGUAGE CPP #-}
34
{-# LANGUAGE DataKinds #-}
45
{-# LANGUAGE FlexibleContexts #-}
56
{-# LANGUAGE FlexibleInstances #-}
@@ -649,12 +650,20 @@ simpleToLink _ toA _ = toLink toA (Proxy :: Proxy sub)
649650
-- >>> import Data.Text (Text)
650651

651652
-- Erroring instance for 'HasLink' when a combinator is not fully applied
652-
instance TypeError (PartialApplication @(Type -> Constraint) HasLink arr) => HasLink ((arr :: a -> b) :> sub)
653+
instance TypeError (PartialApplication
654+
#if __GLASGOW_HASKELL__ >= 904
655+
@(Type -> Constraint)
656+
#endif
657+
HasLink arr) => HasLink ((arr :: a -> b) :> sub)
653658
where
654659
type MkLink (arr :> sub) _ = TypeError (PartialApplication (HasLink :: * -> Constraint) arr)
655660
toLink = error "unreachable"
656661

657662
-- Erroring instances for 'HasLink' for unknown API combinators
658-
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceForSub @(Type -> Constraint) HasLink ty) => HasLink (ty :> sub)
663+
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceForSub
664+
#if __GLASGOW_HASKELL__ >= 904
665+
@(Type -> Constraint)
666+
#endif
667+
HasLink ty) => HasLink (ty :> sub)
659668

660669
instance {-# OVERLAPPABLE #-} TypeError (NoInstanceFor (HasLink api)) => HasLink api

0 commit comments

Comments
 (0)