Code using seq has wrong strictness (too lazy)
Following snippet of code gets miscompiled regardless of optimisation level:
([seq (seq (tail ([]::[Int])) (\a -> error "aaa"))] !! 0) [1]
The result of printing the value is [1], whereas the correct result should be throwing an error:
testModule: Prelude.tail: empty list
The same problem occurs if I try to run the code in GHCI.
Looking at the Core at -O0 suggests that the expression with two seqs gets transformed into the identity function, despite that tail [] could (and will) crash. Since the problem is visible in Core, I mark this bug as independent of the architecture.
I tried it in GHC versions 7.2.1 and 7.3.20111013, which gave same wrong results.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.2.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |