Type family equation with wrong name is silently accepted (GHC 8.6+ only)
Here's a program:
{-# LANGUAGE TypeFamilies #-}
module TypeFamilies where
data A
type family B (x :: *) :: * where
A x = x
One would hope that GHC would reject that nonsensical equation for B
that references A
. On GHC 7.8 through 8.4, that is the case:
$ /opt/ghc/8.4.4/bin/ghci Bug.hs
GHCi, version 8.4.4: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling TypeFamilies ( Bug.hs, interpreted )
Bug.hs:6:3: error:
• Mismatched type name in type family instance.
Expected: B
Actual: A
• In the type family declaration for ‘B’
|
6 | A x = x
| ^^^^^^^
But GHC 8.6.2 and HEAD actually //accept// this program! Thankfully, GHC appears to just treat A x = x
as though you had written B x = x
, so it's not like this breaks type safety or anything. Still, this most definitely ought to be rejected.
One interesting observation is that B
having a CUSK appears to be important. If B
doesn't have a CUSK, as in the following variant:
{-# LANGUAGE TypeFamilies #-}
module TypeFamilies where
data A
type family B x where
A x = x
Then GHC properly catches the mismatched use of A
:
$ /opt/ghc/8.6.2/bin/ghci Bug.hs
GHCi, version 8.6.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling TypeFamilies ( Bug.hs, interpreted )
Bug.hs:6:3: error:
• Mismatched type name in type family instance.
Expected: B
Actual: A
• In the type family declaration for ‘B’
|
6 | A x = x
| ^^^^^^^
Trac metadata
Trac field | Value |
---|---|
Version | 8.6.2 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |