summaryrefslogtreecommitdiff
path: root/testsuite/tests/th/TH_addCStub2.hs
blob: 10119d93703893da10d1cfe5322d4a4e391ccddf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-- Tests that a reasonable error is reported when addCStub is used with
-- incorrect C code.

{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -optc-DA_MACRO=1 #-}

import Language.Haskell.TH.Syntax

foreign import ccall f :: Int -> IO Int

do addCStub $ unlines
     [ "#include <stdio.h>"
     , "int f(int x {"
     , "  printf(\"calling f(%d)\\n\",x);"
     , "  return A_MACRO + x;"
     , "}"
     ]
   return []

main :: IO ()
main = f 2 >>= print