From 54fc7394040e42aea3b088bc6a3d0bb4f6bb533d Mon Sep 17 00:00:00 2001 From: Luite Stegeman Date: Wed, 1 Feb 2023 15:00:29 +0900 Subject: 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) --- compiler/GHC/Tc/Gen/Foreign.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'compiler') 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 -- cgit v1.2.1