Skip to content

Commit f1c0d2c

Browse files
committed
fix: permit newlines between banInstance calls
Prior to this, the following code compiled ``` $(banInstance [t|forall currency. LActSg (Discrete currency) (Sum Integer)|] "(Sum 0 <> Sum 1) <>$ Discrete 1 /= Sum 0 <>$ (Sum 1 <>$ Discrete 1)") $(banInstance [t|forall currency. RActSg (Discrete currency) (Sum Integer)|] "Discrete 1 $<> (Sum 0 <> Sum 1) /= (Discrete 1 $<> Sum 0) $<> Sum 1") ``` but the following produced a type error ``` $(banInstance [t|forall currency. LActSg (Discrete currency) (Sum Integer)|] "(Sum 0 <> Sum 1) <>$ Discrete 1 /= Sum 0 <>$ (Sum 1 <>$ Discrete 1)") $(banInstance [t|forall currency. RActSg (Discrete currency) (Sum Integer)|] "Discrete 1 $<> (Sum 0 <> Sum 1) /= (Discrete 1 $<> Sum 0) $<> Sum 1") ```
1 parent bc05530 commit f1c0d2c

File tree

1 file changed

+13
-3
lines changed
  • src/Language/Haskell/Instance

1 file changed

+13
-3
lines changed

src/Language/Haskell/Instance/Ban.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,28 @@ banInstance constraintQ message = do
5353
':$$: 'Text "Instance banned at " ':<>: 'Text $(symbol $ formatLocation loc)
5454
':$$: 'Text ""
5555
)|]]
56-
pure <$> instanceD context constraintQ (convertClassDecs classDecs)
56+
pure <$> instanceD context (withoutForall <$> constraintQ) (convertClassDecs classDecs)
5757

5858
symbol :: String -> TypeQ
5959
symbol = litT . strTyLit
6060

6161
formatLocation :: Loc -> String
6262
formatLocation Loc{..} = concat ["[", loc_package, ":", loc_module, "] ", loc_filename, ":", show $ fst loc_start]
6363

64+
withoutForall :: Type -> Type
65+
withoutForall topTy = go topTy where
66+
go (ForallT _ _ ty) = ty
67+
go ty = ty
68+
6469
className :: Type -> Name
6570
className topTy = go topTy where
66-
go (AppT ty _) = className ty
67-
go (ConT name) = name
71+
go (ForallT _ _ ty) = className ty
72+
go (ForallVisT _ ty) = className ty
73+
go (AppT ty _) = className ty
74+
go (AppKindT ty _) = className ty
75+
go (SigT ty _) = className ty
76+
go (ConT name) = name
77+
go (ParensT ty) = className ty
6878
go _ = error $ "Cannot determine class name for type: " ++ pprint topTy
6979

7080
convertClassDecs :: [Dec] -> [DecQ]

0 commit comments

Comments
 (0)