Typechecker regression in 8.0.1
This code:
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RoleAnnotations #-}
module Bug where
import Data.Proxy (Proxy(..))
import GHC.Prim (coerce)
class Throws e where {}
type role Throws representational
newtype Wrap e a = Wrap { unWrap :: Throws e => a }
coerceWrap :: Wrap e a -> Wrap (Catch e) a
coerceWrap = coerce
newtype Catch a = Catch a
instance Throws (Catch e) where {}
unthrow :: Proxy e -> (Throws e => a) -> a
unthrow _ = unWrap . coerceWrap . Wrap
compiles fine with ghc 7.10.2 but fails with ghc 8.0.1 with error:
Bug.hs:25:13: error:
* Could not deduce (Throws e)
from the context: Throws e0
bound by a type expected by the context:
Throws e0 => a
at Bug.hs:25:13-38
Possible fix:
add (Throws e) to the context of
the type signature for:
unthrow :: Proxy e -> (Throws e => a) -> a
* In the expression: unWrap . coerceWrap . Wrap
In an equation for `unthrow':
unthrow _ = unWrap . coerceWrap . Wrap
This code is extracted from blog post http://www.well-typed.com/blog/2015/07/checked-exceptions/ and gist https://gist.github.com/edsko/f1f566f77422398fba7d
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | highest |
Resolution | Unresolved |
Component | Compiler (Type checker) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Windows |
Architecture | x86 |