diff options
author | Josh Meredith <joshmeredith2008@gmail.com> | 2023-03-10 16:16:00 +0000 |
---|---|---|
committer | Josh Meredith <joshmeredith2008@gmail.com> | 2023-03-13 03:56:03 +0000 |
commit | 047e9d4f10e4124899887449dc52b9e72a7d3ea6 (patch) | |
tree | 8f30d6843f3c31fb32ac39c12abbee81921fb8ec | |
parent | ec263a59b886ea616dabce349df7a377d5356dd5 (diff) | |
download | haskell-047e9d4f10e4124899887449dc52b9e72a7d3ea6.tar.gz |
JS: fix implementation of forceBool to use JS backend syntaxwip/js-forceBool
-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 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, ['']) |