Ticket #7536 (closed bug: fixed)

Opened 5 months ago

Last modified 5 months ago

Panic with TypeFamilies with type synonym instances

Reported by: snowleopard Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.1
Keywords: Cc: rotsor@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Difficulty: Unknown
Test Case: indexed_types/should_fail/T7536 Blocked By:
Blocking: Related Tickets:

Description

The code below brings GHC to panic.

{-# LANGUAGE TypeFamilies, FlexibleInstances #-}

module Bug where

type Node v = Int

class Predicate a where
   type Var a
   variable :: Var a -> a

instance Predicate (Node v) where
   type Var (Node v) = v
   variable = undefined

Panic details:

ghc: panic! (the 'impossible' happened)
  (GHC version 7.4.2 for i386-unknown-mingw32):
	tcTyVarDetails
    ( v{tv aa3} [tv] :: ghc-prim:GHC.Prim.*{(w) tc 34d} )

Can be reproduced on GHC versions 7.4.2 and 7.6.1.

Possibly, a duplicate of  http://hackage.haskell.org/trac/ghc/ticket/7458, but difficult to tell without additional info on the latter.

Change History

Changed 5 months ago by rotsor

  • summary changed from Panic with TypeFamilies and FlexibleInstances to Panic with TypeFamilies with type synonym instances

I've been able to also reproduce it without type classes:

{-# LANGUAGE TypeFamilies #-}

module M where

type T v = Int

type family TF a :: *
type instance TF (T a) = a

panic :: TF Int
panic = undefined

Changed 5 months ago by simonpj@…

commit e89f3bac94f513841f46346528183920783ce1f9

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Wed Jan 2 08:26:28 2013 +0000

    In type or data instances, check that all variables are bound
    
    Trac #7536 points out that it's possible for the LHS to *look*
    as if it binds variables, but does not acutally do so
    
             type T a = Int
             type instance F (T a) = a
    
    This patch makes it an error.

 compiler/typecheck/TcInstDcls.lhs   |   43 ++++++++++++++++++-----------------
 compiler/typecheck/TcMType.lhs      |   36 ++++++++++++++++++++++-------
 compiler/typecheck/TcTyClsDecls.lhs |   23 ++++++------------
 3 files changed, 57 insertions(+), 45 deletions(-)

Changed 5 months ago by simonpj

  • status changed from new to merge
  • difficulty set to Unknown
  • testcase set to indexed_types/should_fail/T7536

Thanks for pointing this out. I guess this fix is worth merging to the 7.6 branch, if it goes through smoothly.

Simon

Changed 5 months ago by igloo

  • status changed from merge to closed
  • resolution set to fixed

Not smooth, so not merging.

Note: See TracTickets for help on using tickets.