GHC internal error on HEAD with ill-scoped type synonym
Summary
Using GHC HEAD (commit dafc4709), GHC produces an internal error when compiling a type synonym with an out-of-scope kind variable.
Steps to reproduce
Compile the following program with GHC HEAD:
module Bug where
import GHC.Exts (Any)
type Foo :: a
type Foo = Any :: a
$ ~/Software/ghc-9.9.20231012/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:6:19: error: [GHC-76329]
• GHC internal error: ‘a’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [riQ :-> ATcTyCon Foo :: forall a. a]
• In the kind ‘a’
In the type ‘Any :: a’
In the type declaration for ‘Foo’
|
6 | type Foo = Any :: a
| ^
Note that this program will compile with GHC 9.8 and earlier, but that is only because GHC HEAD has implemented !10660 (closed), which removes arity inference in type synonym declarations. Therefore, this bug only makes sense in the context of HEAD.
Expected behavior
I would expect GHC to produce an ordinary error message stating that a
is out of scope, similar to the error message that you get when compiling a similar program with a type family instead of a type synonym:
{-# LANGUAGE TypeAbstractions #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where
import GHC.Exts (Any)
type Bar :: a
type family Bar @a where
Bar = Any :: a
$ ~/Software/ghc-9.9.20231012/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:16: error: [GHC-76037]
Not in scope: type variable ‘a’
|
9 | Bar = Any :: a
| ^
Environment
- GHC version used: HEAD (commit dafc4709)
Optional:
- Operating System: Ubuntu 22.04
- System Architecture: x86_64