diff options
author | Josh Meredith <joshmeredith2008@gmail.com> | 2023-03-10 16:16:00 +0000 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2023-05-15 18:34:25 -0400 |
commit | dc291c003debaaaaf60053078e3171bdc5eaa0ac (patch) | |
tree | 47f82971bf10e7b5409006d2fb6ecf8710b507ee | |
parent | 595edd68d9a93ed5e54bd0e1c50f14b778b458eb (diff) | |
download | haskell-dc291c003debaaaaf60053078e3171bdc5eaa0ac.tar.gz |
JS: fix implementation of forceBool to use JS backend syntax
(cherry picked from commit 047e9d4f10e4124899887449dc52b9e72a7d3ea6)
-rw-r--r-- | compiler/GHC/HsToCore/Foreign/JavaScript.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/javascript/T23101.hs | 22 | ||||
-rw-r--r-- | testsuite/tests/javascript/T23101.stdout | 10 | ||||
-rw-r--r-- | testsuite/tests/javascript/all.T | 4 |
4 files changed, 37 insertions, 1 deletions
diff --git a/compiler/GHC/HsToCore/Foreign/JavaScript.hs b/compiler/GHC/HsToCore/Foreign/JavaScript.hs index 820ab80275..23277da594 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 "$r = !(!$1)" [e] boolTy + let forceBool e = mkJsCall ccall_uniq "((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, ['']) |