diff options
author | Luite Stegeman <stegeman@gmail.com> | 2023-02-01 15:00:29 +0900 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2023-02-23 14:05:44 -0500 |
commit | 54fc7394040e42aea3b088bc6a3d0bb4f6bb533d (patch) | |
tree | 15e3849f70ffdc1c156ea34ada2497e404710f5c | |
parent | e0cfea59a3027a48d4d51b0b80b7b1e42183c274 (diff) | |
download | haskell-54fc7394040e42aea3b088bc6a3d0bb4f6bb533d.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
(cherry picked from commit 1d7c2e4c9d63a7b392024cfcde299849b8d667a8)
-rw-r--r-- | compiler/GHC/Tc/Gen/Foreign.hs | 3 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_compile/T22774.hs | 4 | ||||
-rw-r--r-- | testsuite/tests/ffi/should_compile/all.T | 3 |
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, ['']) + |