Opened 7 years ago

Closed 7 years ago

#4272 closed bug (fixed)

Typechecker loop with type families

Reported by: NickSmallbone Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 6.13
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Compile-time crash Test Case: indexed-types/should_fail/Ttttt4272
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The following code (which I think is ill-typed) causes GHC to hang, both on 6.12.1 and 6.13.20100616:

{-# LANGUAGE TypeFamilies, ScopedTypeVariables, FlexibleContexts #-}
module Crash where

class Family f where
  terms :: f a -> a

class Family (TermFamily a) => TermLike a where
  type TermFamily a :: * -> *

laws :: forall a b. TermLike a => TermFamily a a -> b
laws t = prune t (terms (undefined :: TermFamily a a))

prune :: TermLike a => TermFamily a a -> TermFamily a a -> b
prune = undefined

The compiler still hangs if I remove the typeclass constraints (everything to the left of a =>, I mean), but everything else seems to be necessary for the compiler to loop. Using -dshow-passes shows that it's the typechecker that loops.

Change History (1)

comment:1 Changed 7 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: indexed-types/should_fail/Ttttt4272

The new type checker is coming to life. I've just tried it on your program. Sure enough, it tickled a couple of easily-fixed bugs (thank you) but once those were done it produced a decent error message in a jiffy:

    Occurs check: cannot construct the infinite type:
      a = TermFamily a a
    In the first argument of `terms', namely
        `(undefined :: TermFamily a a)'
    In the second argument of `prune', namely
        `(terms (undefined :: TermFamily a a))'
    In the expression: prune t (terms (undefined :: TermFamily a a))

So I declare this bug fixed. I've added a regression test, so you are imortalised.


Note: See TracTickets for help on using tickets.