Commit ffe2f8d6 authored by Ian Lynagh's avatar Ian Lynagh
Browse files

If an assertion fails, through it rather than a deeper error; fixes #5561

An expression like
    assert False (throw e)
should throw the assertion failure rather than e
parent f878f1be
......@@ -303,9 +303,12 @@ instance Show IOException where
"" -> id
_ -> showString " (" . showString s . showString ")")
-- Note the use of "lazy". This means that
-- assert False (throw e)
-- will throw the assertion failure rather than e. See trac #5561.
assertError :: Addr# -> Bool -> a -> a
assertError str predicate v
| predicate = v
| predicate = lazy v
| otherwise = throw (AssertionFailed (untangle str "Assertion failed"))
unsupportedOperation :: IOError
......
......@@ -5,3 +5,4 @@ test('enumRatio', normal, compile_and_run, [''])
test('tempfiles', normal, compile_and_run, [''])
test('fixed', normal, compile_and_run, [''])
test('quotOverflow', normal, compile_and_run, [''])
test('assert', exit_code(1), compile_and_run, ['-fno-ignore-asserts'])
import Control.Exception
-- We want to get the assertion failure, not the overflow exception.
-- trac #5561.
main :: IO ()
main = let e1 i = throw Overflow
in assert False (e1 5)
assert: assert.hs:9:11-16: Assertion failed
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment