diff --git a/inline-c/src/Language/C/Inline/Context.hs b/inline-c/src/Language/C/Inline/Context.hs index 42d12ed..9284477 100644 --- a/inline-c/src/Language/C/Inline/Context.hs +++ b/inline-c/src/Language/C/Inline/Context.hs @@ -320,10 +320,17 @@ convertType purity cTypes = runMaybeT . go -- We cannot convert standalone prototypes mzero + buildArr :: [TH.Type] -> TH.Type -> TH.Q TH.Type buildArr [] hsRetType = case purity of Pure -> [t| $(return hsRetType) |] IO -> [t| IO $(return hsRetType) |] + buildArr [TH.TupleT 0] hsRetType = + case purity of + Pure -> [t| $(return hsRetType) |] + IO -> [t| IO $(return hsRetType) |] + buildArr (TH.TupleT 0 : hsPars) hsRetType = + fail "C function can only have void parameter as the only parameter" buildArr (hsPar : hsPars) hsRetType = [t| $(return hsPar) -> $(buildArr hsPars hsRetType) |] diff --git a/inline-c/test/Language/C/Inline/ContextSpec.hs b/inline-c/test/Language/C/Inline/ContextSpec.hs index ef3c5f2..71aa754 100644 --- a/inline-c/test/Language/C/Inline/ContextSpec.hs +++ b/inline-c/test/Language/C/Inline/ContextSpec.hs @@ -74,6 +74,10 @@ spec = do shouldBeType (cty "int (*f)(unsigned char, float)") [t| FunPtr (CUChar -> CFloat -> IO CInt) |] + Hspec.it "converts void parameter function pointer" $ do + shouldBeType + (cty "void (*f)(void)") + [t| FunPtr (IO ()) |] Hspec.it "converts complicated function pointers (1)" $ do -- pointer to function returning pointer to function returning int shouldBeType