summaryrefslogtreecommitdiff
path: root/testsuite/tests/ffi
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2019-05-29 11:52:02 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-05-31 23:56:27 -0400
commit45f88494293bea20cc3aca025ee6fe84087987ce (patch)
tree131f6175331925789d69f1d651e3463e21d4c98f /testsuite/tests/ffi
parent1d43d4a3e45d86261fa63591e99749cb7d3f68ed (diff)
downloadhaskell-45f88494293bea20cc3aca025ee6fe84087987ce.tar.gz
Reject nested foralls in foreign imports (#16702)
This replaces a panic observed in #16702 with a simple error message stating that nested `forall`s simply aren't allowed in the type signature of a `foreign import` (at least, not at present). Fixes #16702.
Diffstat (limited to 'testsuite/tests/ffi')
-rw-r--r--testsuite/tests/ffi/should_fail/T16702.hs24
-rw-r--r--testsuite/tests/ffi/should_fail/T16702.stderr29
-rw-r--r--testsuite/tests/ffi/should_fail/all.T1
3 files changed, 54 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_fail/T16702.hs b/testsuite/tests/ffi/should_fail/T16702.hs
new file mode 100644
index 0000000000..bad07c7120
--- /dev/null
+++ b/testsuite/tests/ffi/should_fail/T16702.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE UnliftedFFITypes #-}
+{-# LANGUAGE RankNTypes #-}
+
+module T16702 where
+
+import Foreign.C.Types
+import Foreign.Ptr
+import Data.Kind (Type)
+
+foreign import ccall "math.h pow"
+ c_pow :: CDouble
+ -> forall (a :: Type). CDouble
+ -> forall (b :: Type). CDouble
+
+foreign import ccall "malloc"
+ malloc1 :: CSize -> forall a. IO (Ptr a)
+
+foreign import ccall "malloc"
+ malloc2 :: Show a => CSize -> IO (Ptr a)
+
+foreign import ccall "malloc"
+ malloc3 :: CSize -> Show a => IO (Ptr a)
diff --git a/testsuite/tests/ffi/should_fail/T16702.stderr b/testsuite/tests/ffi/should_fail/T16702.stderr
new file mode 100644
index 0000000000..2ab7c751d0
--- /dev/null
+++ b/testsuite/tests/ffi/should_fail/T16702.stderr
@@ -0,0 +1,29 @@
+
+T16702.hs:12:1: error:
+ • Unacceptable result type in foreign declaration:
+ Unexpected nested forall
+ • When checking declaration:
+ foreign import ccall safe "math.h pow" c_pow
+ :: CDouble
+ -> forall (a :: Type). CDouble -> forall (b :: Type). CDouble
+
+T16702.hs:17:1: error:
+ • Unacceptable result type in foreign declaration:
+ Unexpected nested forall
+ • When checking declaration:
+ foreign import ccall safe "malloc" malloc1
+ :: CSize -> forall a. IO (Ptr a)
+
+T16702.hs:20:1: error:
+ • Unacceptable argument type in foreign declaration:
+ ‘Show a’ cannot be marshalled in a foreign call
+ • When checking declaration:
+ foreign import ccall safe "malloc" malloc2
+ :: Show a => CSize -> IO (Ptr a)
+
+T16702.hs:23:1: error:
+ • Unacceptable argument type in foreign declaration:
+ ‘Show a’ cannot be marshalled in a foreign call
+ • When checking declaration:
+ foreign import ccall safe "malloc" malloc3
+ :: CSize -> Show a => IO (Ptr a)
diff --git a/testsuite/tests/ffi/should_fail/all.T b/testsuite/tests/ffi/should_fail/all.T
index 3bd7b5d909..38273db314 100644
--- a/testsuite/tests/ffi/should_fail/all.T
+++ b/testsuite/tests/ffi/should_fail/all.T
@@ -14,6 +14,7 @@ test('T5664', normal, compile_fail, ['-v0'])
test('T7506', normal, compile_fail, [''])
test('T7243', normal, compile_fail, [''])
test('T10461', normal, compile_fail, [''])
+test('T16702', normal, compile_fail, [''])
# UnsafeReenter tests implementation of an undefined behavior (calling Haskell
# from an unsafe foreign function) and only makes sense in non-threaded way