faylang / fay

A proper subset of Haskell that compiles to JavaScript
https://github.com/faylang/fay/wiki
BSD 3-Clause "New" or "Revised" License
1.29k stars 86 forks source link

Passing records containg list to strict module fails depending on argument order #418

Closed robinp closed 9 years ago

robinp commented 9 years ago

Bug.hs:

module Main where

import qualified Fay.Text as T

data Rec = Rec { unRec :: [Int] }
  deriving (Show)

f1 :: Rec -> T.Text -> Fay ()
f1 r t = do
  putStrLn . T.unpack $ t
  putStrLn . show . length . unRec $ r
  putStrLn . show $ r

f2 :: T.Text -> Rec -> Fay ()  -- only difference in arg order
f2 t r = f1 r t

bug.html:

<!doctype html>
<html>
  <head>
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
    <script type="text/javascript" src="bug.js"></script>
    <script>
      window.onload = function() {
        rec = {"instance": "Rec", "unRec": [1,2]}
        console.log("f2")
        Strict.Main.f2("apple", rec)
        console.log("f1")
        Strict.Main.f1(rec , "apple")
      };
    </script>
  </head>
  <body>
  </body>
</html>

compile: fay src/client/Bug.hs --include src/client -o generated/bug.js --strict Main --library --package fay-text

console output: f2 apple 0 {"instance":"Rec","unRec":[]} <--- fail to unserialize inside list f1 apple 2 {"instance":"Rec","unRec":[1,2]}

robinp commented 9 years ago

Note: this is a problem with the strictness wrapper, since calling either function from Fay works as expected.

bergmark commented 9 years ago

This is a duplicate of #409 which contains a workaround. The conversion from JS array to list is what causes the issue