Skip to content

Explicit foralls in associated type family equations are oblivious to class-bound variables

This doesn't typecheck on GHC HEAD:

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where

class C a where
  type T a b

instance C (Maybe a) where
  type forall b. T (Maybe a) b = Either a b
$ ~/Software/ghc/inplace/bin/ghc-stage2 Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

Bug.hs:9:3: error:
    The RHS of an associated type declaration mentions out-of-scope variable ‘a’
      All such variables must be bound on the LHS
  |
9 |   type forall b. T (Maybe a) b = Either a b
  |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

But it ought to. a isn't out of scope at all—it's bound by the class head instance C (Maybe a).

Trac metadata
Trac field Value
Version 8.7
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC mayac
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information