Ticket #5452 (closed bug: fixed)

Opened 21 months ago

Last modified 21 months ago

reify yields incorrect TupleT at higher-kinds

Reported by: nicolas.frisby Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Difficulty:
Test Case: th/T5452 Blocked By:
Blocking: Related Tickets:

Description

Line 1175 of changeset:0237ed6762fc86d0eb5db02a8e02ebe35d8d7272 introduces a bug where reify yields an application of TupleT where its argument is too small when the type being reified is of a higher-kind than *.

For example, in the Applicative instance for ((,) a); the (,) gets reified as TupleT 1 instead of TupleT 2.

Here's some code that duplicates its C instance to be a D instance.

{-# LANGUAGE TemplateHaskell, KindSignatures, FlexibleInstances #-}

module ReifyTupleBug where

import Language.Haskell.TH

class C (f :: * -> *)
class D (f :: * -> *)

instance C ((,) Int)

reify ''C >>= \(ClassI _ [i]) ->
  return [InstanceD (ci_cxt i) (foldl AppT (ConT ''D) (ci_tys i)) []]

It results in a kind mis-match:

ReifyTupleBug.hs:13:1:                                                                                                                                                                                           
    Kind mis-match
    The first argument of `D' should have kind `* -> *',
    but `Int' has kind `*'
    In the instance declaration for `D Int'
Failed, modules loaded: none.}}}

I'm not sure how `reify_tc_app` should be adjusted; perhaps it needs to know the kind at which it is operating and then increment `n_tys` based on the number of arrows?

Change History

Changed 21 months ago by simonpj@…

commit fe9d5227a39ca4b756869842ace299a9736f8068

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri Sep 2 09:08:21 2011 +0100

    Fix a buglet in reification of tuples (fixes Trac #5452)

 compiler/typecheck/TcSplice.lhs |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

Changed 21 months ago by simonpj

  • status changed from new to closed
  • testcase set to th/T5452
  • resolution set to fixed

Thanks! A silly bug, now fixed, test added.

Note: See TracTickets for help on using tickets.