summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuite Stegeman <stegeman@gmail.com>2023-02-01 15:00:29 +0900
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-03-02 22:42:45 -0500
commit8919f34102cae1ff3bae95b7f53e5d93dbad7ecf (patch)
tree715699a24bb50e5691621d2a75100b1c88034048
parent1ed573a53ee454db240b9fb1a17e28c97b6eb53a (diff)
downloadhaskell-8919f34102cae1ff3bae95b7f53e5d93dbad7ecf.tar.gz
Check for platform support for JavaScript foreign imports
GHC was accepting `foreign import javascript` declarations on non-JavaScript platforms. This adds a check so that these are only supported on an platform that supports the JavaScript calling convention. Fixes #22774
-rw-r--r--compiler/GHC/Tc/Gen/Foreign.hs3
-rw-r--r--testsuite/tests/ffi/should_compile/T22774.hs4
-rw-r--r--testsuite/tests/ffi/should_compile/all.T3
3 files changed, 9 insertions, 1 deletions
diff --git a/compiler/GHC/Tc/Gen/Foreign.hs b/compiler/GHC/Tc/Gen/Foreign.hs
index caa7feeca7..31c42f86d6 100644
--- a/compiler/GHC/Tc/Gen/Foreign.hs
+++ b/compiler/GHC/Tc/Gen/Foreign.hs
@@ -341,9 +341,10 @@ tcCheckFIType arg_tys res_ty idecl@(CImport src (L lc cconv) (L ls safety) mh
checkForeignRes nonIOok checkSafe (isFFIPrimResultTy dflags) res_ty
return (CImport src (L lc cconv) (L ls safety) mh (CFunction target))
| cconv == JavaScriptCallConv = do
+ cconv' <- checkCConv (Right idecl) cconv
checkCg (Right idecl) backendValidityOfCImport
-- leave the rest to the JS backend (at least for now)
- return (CImport src (L lc cconv) (L ls safety) mh (CFunction target))
+ return (CImport src (L lc cconv') (L ls safety) mh (CFunction target))
| otherwise = do -- Normal foreign import
checkCg (Right idecl) backendValidityOfCImport
cconv' <- checkCConv (Right idecl) cconv
diff --git a/testsuite/tests/ffi/should_compile/T22774.hs b/testsuite/tests/ffi/should_compile/T22774.hs
new file mode 100644
index 0000000000..a100aeffb7
--- /dev/null
+++ b/testsuite/tests/ffi/should_compile/T22774.hs
@@ -0,0 +1,4 @@
+module T22774 where
+
+foreign import javascript foo :: IO ()
+
diff --git a/testsuite/tests/ffi/should_compile/all.T b/testsuite/tests/ffi/should_compile/all.T
index 6b4c557a07..43756349d9 100644
--- a/testsuite/tests/ffi/should_compile/all.T
+++ b/testsuite/tests/ffi/should_compile/all.T
@@ -44,3 +44,6 @@ test(
)
test('T15531', normal, compile, ['-Wall'])
test('T22043', [omit_ways(['ghci'])], compile, [''])
+
+test('T22774', when(not js_arch(), expect_fail), compile, [''])
+