Skip to content

Instance declarations don't recognize named wildcards

While exploring a fix for #13324 (closed), I was blocked pretty quickly by this limitation: instance declarations don't properly recognize named wildcards. Here is an example to demonstrate:

{-# LANGUAGE NamedWildCards #-}
module Bug where

instance _x => Show (Maybe a)
Bug.hs:4:10: error:
    • Illegal constraint: _x (Use ConstraintKinds to permit this)
    • In the context: _x
      While checking an instance declaration
      In the instance declaration for ‘Show (Maybe a)’
  |
4 | instance _x => Show (Maybe a)
  |          ^^^^^^^^^^^^^^^^^^^^

GHC doesn't recognize that _x is just a type variable, not a named wildcard.

I believe fixing this is just a matter of changing the ASTs for instance declarations to use LHsSigWcType instead of LHsSigType. Patch incoming.

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