From 4a74cc65047f03154f392b72e5d0f19ec57b23e7 Mon Sep 17 00:00:00 2001 From: sorki Date: Fri, 15 Dec 2023 18:13:21 +0100 Subject: [PATCH] Avoid -Wincomplete-uni-patterns in generated splices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) ``` --- Language/C/Quote/Base.hs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Language/C/Quote/Base.hs b/Language/C/Quote/Base.hs index 398879a..86a0b17 100644 --- a/Language/C/Quote/Base.hs +++ b/Language/C/Quote/Base.hs @@ -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)