Opened 4 years ago

Closed 4 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 Difficulty:
Test Case: indexed-types/should_fail/Ttttt4272 Blocked By:
Blocking: Related Tickets:

Description

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 4 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to 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:

T4272.hs:11:26:
    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.

Simon

Note: See TracTickets for help on using tickets.