Skip to content

ghc 8.4.1 lifts errors out of if then else

Ok, here's a short module:

import qualified Control.Exception as Exception

main :: IO ()
main = do
    unserialize
    putStrLn "all is well"

unserialize :: IO Char
unserialize =
    if definitelyTrue
        then do
            return 'a'
        else do
            Exception.evaluate (error "wrong place")

{-# NOINLINE definitelyTrue #-}
definitelyTrue :: Bool
definitelyTrue = True

When compiled with -O on 8.4.1, this should print "wrong place". Without -O, or with 8.4.2, or if True can be inlined, or without evaluate, all is well. I can reproduce this on OS X 10.13.4.

This could be related to a known bug with Exception.evaluate in 8.4.1: #13930 (closed)

Edited by elaforge
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information