valderman / haste-compiler

A GHC-based Haskell to JavaScript compiler
http://haste-lang.org
BSD 3-Clause "New" or "Revised" License
1.45k stars 115 forks source link

compiler bug involving MVar, Integer, and tuples #412

Open blynn opened 6 years ago

blynn commented 6 years ago

The following generates JavaScript that crashes due to an Uncaught ReferenceError involving what seems to be a generated symbol (e.g. "_l2"). It succeeds if compiled with --ddisable-js-opts.

import Control.Concurrent.MVar
import Data.Array

main :: IO ()
main = do
  let r = ((0,0), (7,7))
  mv <- newEmptyMVar
  putMVar mv True
  b <- takeMVar mv
  if b then do
    putStrLn "crashes here"
    putStrLn $ show [inRange r (0 + x, 7 + y) | x <- [-1, 1], y <- [-1, 1]]
    putStrLn "...unless compiled with --ddisable-js-opts"
  else undefined

I tried finding a smaller example, but I found the crash disappeared if:

Hopefully the above is enough to go on.