Opened 2 years ago

Closed 2 years ago

#6081 closed bug (fixed)

Kind variables not allowed in class instance declarations

Reported by: goldfire Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.5
Keywords: PolyKinds Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: polykinds/T6081 Blocked By:
Blocking: Related Tickets: #6064

Description

Consider the following code:

{-# LANGUAGE KindSignatures, PolyKinds, DataKinds, RankNTypes #-}

data KProxy (a :: *) = KP

class KindClass (kp :: KProxy k)
instance KindClass (KP :: KProxy [k])

The last line fails to compile, producing the following error message:

  Not in scope: type variable `k'

However, there is a workaround. When I change the last line to

instance forall (a :: k). KindClass (KP :: KProxy [k])

all is good. Unfortunately, this last line requires the declaration of an unused type variable a, which is a little messy.

This was tested on 7.5.20120426.

Change History (3)

comment:1 Changed 2 years ago by goldfire

comment:2 Changed 2 years ago by simonpj@…

commit fc8959acae02605c71b775c8d403e38b5cc6fecd

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri May 11 18:02:18 2012 +0100

    Refactor LHsTyVarBndrs to fix Trac #6081
    
    This is really a small change, but it touches a lot of files quite
    significantly. The real goal is to put the implicitly-bound kind
    variables of a data/class decl in the right place, namely on the
    LHsTyVarBndrs type, which now looks like
    
      data LHsTyVarBndrs name
        = HsQTvs { hsq_kvs :: [Name]
                 , hsq_tvs :: [LHsTyVarBndr name]
          }
    
    This little change made the type checker neater in a number of
    ways, but it was fiddly to push through the changes.

 compiler/deSugar/DsMeta.hs          |   43 +++---
 compiler/hsSyn/Convert.lhs          |   22 ++--
 compiler/hsSyn/HsDecls.lhs          |   32 ++--
 compiler/hsSyn/HsPat.lhs            |    4 +-
 compiler/hsSyn/HsTypes.lhs          |  126 +++++++++--------
 compiler/hsSyn/HsUtils.lhs          |    5 +-
 compiler/parser/Parser.y.pp         |    8 +-
 compiler/parser/ParserCore.y        |   10 +-
 compiler/parser/RdrHsSyn.lhs        |   25 ++--
 compiler/rename/RnBinds.lhs         |    2 +-
 compiler/rename/RnEnv.lhs           |   17 ++-
 compiler/rename/RnPat.lhs           |    4 +-
 compiler/rename/RnSource.lhs        |   81 +++++------
 compiler/rename/RnTypes.lhs         |  264 +++++++++++++++++++++--------------
 compiler/typecheck/TcEvidence.lhs   |    3 +-
 compiler/typecheck/TcHsType.lhs     |   41 +++---
 compiler/typecheck/TcRnDriver.lhs   |    9 +-
 compiler/typecheck/TcSMonad.lhs     |   61 ++++----
 compiler/typecheck/TcTyClsDecls.lhs |   31 ++--
 19 files changed, 422 insertions(+), 366 deletions(-)

comment:3 Changed 2 years ago by simonpj

  • Difficulty set to Unknown
  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to polykinds/T6081

I've added a regression test now.

Note: See TracTickets for help on using tickets.