Opened 9 years ago

Closed 9 years ago

#2888 closed merge (fixed)

Source file that compiled fine no longer compiles after touching it.

Reported by: Eelis- Owned by: igloo
Priority: normal Milestone:
Component: Compiler Version: 6.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: indexed-types/should_fail/T2888
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In the following session, t.hs first compiles fine, then after being touched, no longer does:

  eelis ~/sand : cat M.hs
  {-# LANGUAGE TypeFamilies #-}
  module M where
  class C a where data D :: * -> *

  eelis ~/sand : cat t.hs
  {-# LANGUAGE TypeFamilies #-}
  import M
  data Bla = Bla
  instance C Bla where data D a = D
  main = return ()

  eelis ~/sand : ghc --make t.hs
  [1 of 2] Compiling M                ( M.hs, M.o )
  [2 of 2] Compiling Main             ( t.hs, t.o )
  Linking t ...

  eelis ~/sand : touch t.hs

  eelis ~/sand : ghc --make t.hs
  [2 of 2] Compiling Main             ( t.hs, t.o )

      Type indexes must match class instance head
      Found a but expected Bla
      In the associated type instance for `D'
      In the instance declaration for `C Bla'

It seems to me that t.hs should either compile both times, or not compile at all, but not only part of the time.

Change History (3)

comment:1 Changed 9 years ago by simonpj

difficulty: Unknown
Owner: set to simonpj

Excellent bug. Patch coming.

In fact, your class declaration is bogus, and will in future be rejected, because you have not given any type indices to D. You want

  class C a where { data D a :: * }

This wasn't the bug in GHC, mind you. If you are interested, read Note [Avoid name clashes for associated data types] in TcHsType.

I've added a test T2888, but it simply tests the new error message when there are no type indices at all. I'm not sure it's worth the bother to set up a multi-module test to reproduce the original bug.


comment:2 Changed 9 years ago by simonpj

Owner: changed from simonpj to igloo
Test Case: indexed-types/should_fail/T2888
Type: bugmerge

Here's the patch:

Tue Dec 30 16:44:32 GMT 2008
  * Avoid nasty name clash with associated data types (fixes Trac #2888)
  The main bug was in TcHsType; see Note [Avoid name clashes for 
  associated data types].  However I did a bit of re-factoring while 
  I was about it.

Not in the commit message (accidentally) but I added a test for empty type indices. Currently it's an error not a warning.

Pls merge


comment:3 Changed 9 years ago by igloo

Resolution: fixed
Status: newclosed


Note: See TracTickets for help on using tickets.