Skip to content

Commit a731689

Browse files
committed
Make current type name optional in getInstances
1 parent 8a1c5a9 commit a731689

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

hs-bindgen/src-internal/HsBindgen/Backend/Hs/Translation.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ structDecs opts haddockConfig info struct spec fields = do
241241
-- #1286.
242242
where
243243
insts :: Set Hs.TypeClass
244-
insts = Hs.getInstances instanceMap structName candidateInsts $
244+
insts = Hs.getInstances instanceMap (Just structName) candidateInsts $
245245
Hs.fieldType <$> Vec.toList structFields
246246

247247
hsStruct :: Hs.Struct n
@@ -503,7 +503,7 @@ unionDecs haddockConfig info union spec = do
503503
getAccessorDecls :: C.UnionField -> [Hs.Decl]
504504
getAccessorDecls C.UnionField{..} =
505505
let hsType = Type.topLevel unionFieldType
506-
fInsts = Hs.getInstances instanceMap newtypeName insts [hsType]
506+
fInsts = Hs.getInstances instanceMap (Just newtypeName) insts [hsType]
507507
getterName = "get_" <> C.nameHs (C.fieldName unionFieldInfo)
508508
setterName = "set_" <> C.nameHs (C.fieldName unionFieldInfo)
509509
commentRefName name = Just $ HsDoc.paragraph [
@@ -822,7 +822,7 @@ typedefDecs opts haddockConfig info typedef spec = do
822822
insts =
823823
Hs.getInstances
824824
instanceMap
825-
newtypeName
825+
(Just newtypeName)
826826
candidateInsts
827827
[Hs.fieldType newtypeField]
828828

@@ -979,7 +979,7 @@ macroDecsTypedef opts haddockConfig info macroType spec = do
979979
fieldType = Type.topLevel ty
980980

981981
insts :: Set Hs.TypeClass
982-
insts = Hs.getInstances instanceMap newtypeName candidateInsts [fieldType]
982+
insts = Hs.getInstances instanceMap (Just newtypeName) candidateInsts [fieldType]
983983

984984
hsNewtype :: Hs.Newtype
985985
hsNewtype = Hs.Newtype {
@@ -1530,7 +1530,7 @@ constGetter ty instsMap info pureStubName = concat [
15301530
-- superclass constraints. See issue #993.
15311531
Hs.Storable
15321532
`elem`
1533-
Hs.getInstances instsMap "unused" (Set.singleton Hs.Storable) [ty]
1533+
Hs.getInstances instsMap Nothing (Set.singleton Hs.Storable) [ty]
15341534
]
15351535
where
15361536
-- *** Getter ***

hs-bindgen/src-internal/HsBindgen/Backend/Hs/Translation/Instances.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ type InstanceMap = Map (Name NsTypeConstr) (Set TypeClass)
1818

1919
getInstances ::
2020
HasCallStack
21-
=> InstanceMap -- ^ Current state
22-
-> Name NsTypeConstr -- ^ Name of current type
23-
-> Set TypeClass -- ^ Candidate instances
24-
-> [HsType] -- ^ Dependencies
21+
=> InstanceMap -- ^ Current state
22+
-> Maybe (Name NsTypeConstr) -- ^ Name of current type (optionaL)
23+
-> Set TypeClass -- ^ Candidate instances
24+
-> [HsType] -- ^ Dependencies
2525
-> Set TypeClass
2626
getInstances instanceMap name = aux
2727
where
@@ -32,7 +32,7 @@ getInstances instanceMap name = aux
3232
| otherwise = case hsType of
3333
HsPrimType primType -> aux (acc /\ hsPrimTypeInsts primType) hsTypes
3434
HsTypRef name'
35-
| name' == name -> aux acc hsTypes
35+
| Just name' == name -> aux acc hsTypes
3636
| otherwise -> case Map.lookup name' instanceMap of
3737
Just instances -> aux (acc /\ instances) hsTypes
3838
Nothing -> panicPure $ "type not found: " ++ show name'

0 commit comments

Comments
 (0)