Bounded Enums [minBound..maxBound] produces runtime error
Consider this code:
data MultiHeader
= MultiHeaderCacheControl
| MultiHeaderConnection
| MultiHeaderContentEncoding
-- ...
deriving (Show, Eq, Enum, Bounded, Generic)
instance Hashable MultiHeader
multiHeaderCI :: MultiHeader -> CI.CI BS.ByteString
multiHeaderCI mh =
case mh of
MultiHeaderCacheControl -> "Cache-Control"
MultiHeaderConnection -> "Connection"
MultiHeaderContentEncoding -> "Content-Encoding"
-- ...
multiHeaderMap :: HM.HashMap (CI.CI BS.ByteString) MultiHeader
multiHeaderMap =
HM.fromList $ flip map [minBound..maxBound] $ \mh ->
(multiHeaderCI mh, mh)
(derived from https://github.com/agrafix/Spock/blob/9c19c0159d99783aabf896d2742e231a5e85e0a5/src/Web/Spock/Internal/Wire.hs#L83-L121 )
When the multiHeaderMap accessed, a runtime error on GHC7.10.2 running on *some* [0] [1] Linux architectures is thrown. It does not occur on Mac or the travis build infrastructure [2].
uncaught exception: ErrorCall (toEnum{MultiHeader}: tag (-12565) is outside of enumeration's range (0,12))
I've marked the bug with 'core libraries', but I am not certain that that's the origin of it.
[0]: https://github.com/agrafix/Spock/issues/44 (Hydra / NixOS?) [1]: We've also seen it happen when used in docker with ubuntu:14.04 base image [2]: https://travis-ci.org/agrafix/Spock/builds/76877783
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.10.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Core Libraries |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |