1- {-# language TemplateHaskellQuotes #-}
1+ {-# language NamedFieldPuns #-}
22{-# language NoStarIsType #-}
3+ {-# language TemplateHaskellQuotes #-}
4+
35module Render.Type
46 ( Preserve (.. )
57 , ExtensibleStructStyle (.. )
@@ -15,6 +17,7 @@ module Render.Type
1517 , ConstrainedVar (.. )
1618 ) where
1719
20+ import qualified Data.List as L
1821import qualified Data.Text as T
1922import qualified Data.Vector as V
2023import Foreign.C.Types
@@ -48,7 +51,7 @@ import Spec.Types
4851-- | The same as 'cToHsType' except type variables are written as @_@
4952cToHsTypeWithHoles
5053 :: forall r
51- . (HasErr r , HasRenderParams r , HasSpecInfo r )
54+ . (HasErr r , HasRenderParams r , HasSpecInfo r , HasCallStack )
5255 => Preserve
5356 -> CType
5457 -> Sem r H. Type
@@ -57,7 +60,7 @@ cToHsTypeWithHoles = runNoContext .: cToHsType' UnwrappedHole
5760-- | The same as 'cToHsType' except extensible structs are wrapped in @SomeStruct@
5861cToHsTypeWrapped
5962 :: forall r
60- . (HasErr r , HasRenderParams r , HasSpecInfo r )
63+ . (HasErr r , HasRenderParams r , HasSpecInfo r , HasCallStack )
6164 => Preserve
6265 -> CType
6366 -> Sem r H. Type
@@ -85,7 +88,7 @@ cToHsTypeWithContext = cToHsType' Unwrapped
8588
8689cToHsType
8790 :: forall r
88- . (HasErr r , HasRenderParams r , HasSpecInfo r )
91+ . (HasErr r , HasRenderParams r , HasSpecInfo r , HasCallStack )
8992 => Preserve
9093 -> CType
9194 -> Sem r H. Type
@@ -212,6 +215,7 @@ data ContextState = ContextState
212215 , csPositiveVars :: [ConstrainedVar ]
213216 , csNextVars :: [Name ]
214217 }
218+ deriving (Show )
215219
216220type HasContextState r = Member (State ContextState ) r
217221
@@ -251,13 +255,17 @@ runRenderTypeContext a = do
251255 (s, r) <- runState initialContextState a
252256 pure (reverse (csNegativeVars s), reverse (csPositiveVars s), r)
253257
254- runNoContext :: HasErr r => Sem (State ContextState : r ) a -> Sem r a
258+ runNoContext :: ( HasErr r , HasCallStack ) => Sem (State ContextState : r ) a -> Sem r a
255259runNoContext a = do
256- (s, r) <- runState initialContextState a
257- if null (csNegativeVars s <> csPositiveVars s)
258- then pure ()
259- else throw " Variables were inserted while getting the type with no context"
260- pure r
260+ (ContextState {csNegativeVars, csPositiveVars}, r) <- runState initialContextState a
261+ if null (csNegativeVars <> csPositiveVars)
262+ then pure r
263+ else throw . fromString $ L. unlines
264+ [ " Variables were inserted while getting the type with no context:"
265+ , ' -' : show csNegativeVars
266+ , ' +' : show csPositiveVars
267+ , prettyCallStack callStack
268+ ]
261269
262270----------------------------------------------------------------
263271-- Utils
0 commit comments