From 047e9d4f10e4124899887449dc52b9e72a7d3ea6 Mon Sep 17 00:00:00 2001 From: Josh Meredith Date: Fri, 10 Mar 2023 16:16:00 +0000 Subject: JS: fix implementation of forceBool to use JS backend syntax --- compiler/GHC/HsToCore/Foreign/JavaScript.hs | 2 +- testsuite/tests/javascript/T23101.hs | 22 ++++++++++++++++++++++ testsuite/tests/javascript/T23101.stdout | 10 ++++++++++ testsuite/tests/javascript/all.T | 4 ++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/javascript/T23101.hs create mode 100644 testsuite/tests/javascript/T23101.stdout create mode 100644 testsuite/tests/javascript/all.T diff --git a/compiler/GHC/HsToCore/Foreign/JavaScript.hs b/compiler/GHC/HsToCore/Foreign/JavaScript.hs index 130de83ebf..62ea86ee9a 100644 --- a/compiler/GHC/HsToCore/Foreign/JavaScript.hs +++ b/compiler/GHC/HsToCore/Foreign/JavaScript.hs @@ -639,7 +639,7 @@ jsResultWrapper result_ty | Just (tc,_) <- maybe_tc_app, tc `hasKey` boolTyConKey = do -- result_id <- newSysLocalDs boolTy ccall_uniq <- newUnique - let forceBool e = mkJsCall ccall_uniq (fsLit "$r = !(!$1)") [e] boolTy + let forceBool e = mkJsCall ccall_uniq (fsLit "((x) => { return !(!x); })") [e] boolTy return (Just intPrimTy, \e -> forceBool e) diff --git a/testsuite/tests/javascript/T23101.hs b/testsuite/tests/javascript/T23101.hs new file mode 100644 index 0000000000..4aad09d64e --- /dev/null +++ b/testsuite/tests/javascript/T23101.hs @@ -0,0 +1,22 @@ + +foreign import javascript "(($1) => { return $1; })" + bool_id :: Bool -> Bool + +foreign import javascript "(($1) => { return !$1; })" + bool_not :: Bool -> Bool + +foreign import javascript "(($1) => { console.log($1); })" + bool_log :: Bool -> IO () + +main :: IO () +main = do + bool_log True + bool_log False + bool_log (bool_id True) + bool_log (bool_id False) + bool_log (bool_not True) + bool_log (bool_not False) + print (bool_id True) + print (bool_id False) + print (bool_not True) + print (bool_not False) diff --git a/testsuite/tests/javascript/T23101.stdout b/testsuite/tests/javascript/T23101.stdout new file mode 100644 index 0000000000..b826e457fe --- /dev/null +++ b/testsuite/tests/javascript/T23101.stdout @@ -0,0 +1,10 @@ +true +false +true +false +false +true +True +False +False +True diff --git a/testsuite/tests/javascript/all.T b/testsuite/tests/javascript/all.T new file mode 100644 index 0000000000..6ff2a7818a --- /dev/null +++ b/testsuite/tests/javascript/all.T @@ -0,0 +1,4 @@ +# These are JavaScript-specific tests +setTestOpts(when(not(js_arch()),skip)) + +test('T23101', normal, compile_and_run, ['']) -- cgit v1.2.1