Skip to content

Commit 6ebb9e4

Browse files
authored
Fix overlapping MimeRender instances (#1376)
1 parent 505e6d3 commit 6ebb9e4

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

servant/src/Servant/API/UVerb.hs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
import Data.Proxy (Proxy (Proxy))
3737
import GHC.TypeLits (Nat)
3838
import Network.HTTP.Types (Status, StdMethod)
39-
import Servant.API.ContentTypes (NoContent, MimeRender(mimeRender), MimeUnrender(mimeUnrender))
39+
import Servant.API.ContentTypes (JSON, PlainText, FormUrlEncoded, OctetStream, NoContent, MimeRender(mimeRender), MimeUnrender(mimeUnrender))
4040
import Servant.API.Status (KnownStatus, statusVal)
4141
import Servant.API.UVerb.Union
4242

@@ -69,13 +69,6 @@ instance (HasStatus a, HasStatuses as) => HasStatuses (a ': as) where
6969
newtype WithStatus (k :: Nat) a = WithStatus a
7070
deriving (Eq, Show)
7171

72-
instance MimeRender ctype a => MimeRender ctype (WithStatus _status a) where
73-
mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
74-
75-
instance MimeUnrender ctype a => MimeUnrender ctype (WithStatus _status a) where
76-
mimeUnrender contentTypeProxy input =
77-
WithStatus <$> mimeUnrender contentTypeProxy input
78-
7972
-- | an instance of this typeclass assigns a HTTP status code to a return type
8073
--
8174
-- Example:
@@ -105,3 +98,27 @@ instance KnownStatus n => HasStatus (WithStatus n a) where
10598
-- Backwards compatibility is tricky, though: this type alias would mean people would have to
10699
-- use 'respond' instead of 'pure' or 'return', so all old handlers would have to be rewritten.
107100
data UVerb (method :: StdMethod) (contentTypes :: [*]) (as :: [*])
101+
102+
instance {-# OVERLAPPING #-} MimeRender JSON a => MimeRender JSON (WithStatus _status a) where
103+
mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
104+
105+
instance {-# OVERLAPPING #-} MimeRender PlainText a => MimeRender PlainText (WithStatus _status a) where
106+
mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
107+
108+
instance {-# OVERLAPPING #-} MimeRender FormUrlEncoded a => MimeRender FormUrlEncoded (WithStatus _status a) where
109+
mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
110+
111+
instance {-# OVERLAPPING #-} MimeRender OctetStream a => MimeRender OctetStream (WithStatus _status a) where
112+
mimeRender contentTypeProxy (WithStatus a) = mimeRender contentTypeProxy a
113+
114+
instance {-# OVERLAPPING #-} MimeUnrender JSON a => MimeUnrender JSON (WithStatus _status a) where
115+
mimeUnrender contentTypeProxy input = WithStatus <$> mimeUnrender contentTypeProxy input
116+
117+
instance {-# OVERLAPPING #-} MimeUnrender PlainText a => MimeUnrender PlainText (WithStatus _status a) where
118+
mimeUnrender contentTypeProxy input = WithStatus <$> mimeUnrender contentTypeProxy input
119+
120+
instance {-# OVERLAPPING #-} MimeUnrender FormUrlEncoded a => MimeUnrender FormUrlEncoded (WithStatus _status a) where
121+
mimeUnrender contentTypeProxy input = WithStatus <$> mimeUnrender contentTypeProxy input
122+
123+
instance {-# OVERLAPPING #-} MimeUnrender OctetStream a => MimeUnrender OctetStream (WithStatus _status a) where
124+
mimeUnrender contentTypeProxy input = WithStatus <$> mimeUnrender contentTypeProxy input

0 commit comments

Comments
 (0)