Skip to content

Commit

Permalink
Avoid -Wincomplete-uni-patterns in generated splices
Browse files Browse the repository at this point in the history
Resolves warnings coming from TH splices, like

```haskell
src/Ivory/Compile/C/Gen.hs:314:25: warning: [GHC-62161] [-Wincomplete-uni-patterns]
    Pattern match(es) are non-exhaustive
    In a pattern binding:
        Patterns of type ‘C.Type’ not matched:
            C.AntiType _ _
            C.Type (C.AntiDeclSpec _ _) _ _
            C.Type (C.AntiTypeDeclSpec _ _ _ _) _ _
    |
314 |       [C.BlockStm [cstm| for( $ty:(toType ty) $id:(toVar var)
```
  • Loading branch information
sorki committed Dec 16, 2023
1 parent 3da046a commit 2eb249d
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Language/C/Quote/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,30 @@ qqIdE _ = Nothing
qqDeclSpecE :: C.DeclSpec -> Maybe (Q Exp)
qqDeclSpecE (C.AntiDeclSpec v _) = Just $ antiVarE v
qqDeclSpecE (C.AntiTypeDeclSpec extraStorage extraTypeQuals v _) =
Just [|let C.Type (C.DeclSpec storage typeQuals typeSpec loc) _ _
= $(antiVarE v)
in
C.DeclSpec (storage ++ $(dataToExpQ qqExp extraStorage))
(typeQuals ++ $(dataToExpQ qqExp extraTypeQuals))
typeSpec
loc
Just [|
case $(antiVarE v) of
C.Type (C.DeclSpec storage typeQuals typeSpec loc) _ _ ->
C.DeclSpec
(storage ++ $(dataToExpQ qqExp extraStorage))
(typeQuals ++ $(dataToExpQ qqExp extraTypeQuals))
typeSpec
loc

x -> error
$ "Impossible happened, expected C.Type (C.DeclSpec {}) but got "
++ show x
|]
qqDeclSpecE _ = Nothing

qqDeclE :: C.Decl -> Maybe (Q Exp)
qqDeclE (C.AntiTypeDecl v _) =
Just [|let C.Type _ decl _ = $(antiVarE v) in decl|]
Just [|
case $(antiVarE v) of
C.Type _ decl _ -> decl
x -> error
$ "Impossible happened, expected C.Type but got "
++ show x
|]
qqDeclE _ = Nothing

qqTypeQualE :: C.TypeQual -> Maybe (Q Exp)
Expand Down

0 comments on commit 2eb249d

Please sign in to comment.