Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#5514 closed bug (fixed)

bad variable escape analysis when TypeFamilies are enabled

Reported by: dmwit Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_compile/T5514
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The following minimal example causes a type error in 7.3.20110927:

{-# LANGUAGE TypeFamilies #-}

class Foo a where
	foo :: a -> a

instance (Foo a, Foo b) => Foo (a, b) where
	foo = foo' ()

foo' es = const id (unitId es)

unitId :: () -> ()
unitId = id

Specifically, the error given is:

    Couldn't match type `a0' with `(a, b)'
      because type variables `a', `b' would escape their scope
    These (rigid, skolem) type variables are bound by
      the instance declaration
    The following variables have types that mention a0
      foo' :: () -> a0 -> a0 (bound at test.hs:9:1)
    In the instance declaration for `Foo (a, b)'

This code compiles successfully as recently as 7.3.20110726 (though I haven't tested any GHC versions in between these two).

Change History (5)

comment:1 Changed 5 years ago by dmwit

Actually, the example can be made even a bit simpler by replacing the line

instance (Foo a, Foo b) => Foo (a, b) where

by the line

instance Foo [a] where

if that simplification seems helpful.

comment:2 Changed 5 years ago by simonpj

I'm on it.

comment:3 Changed 5 years ago by simonpj@…

commit 9aa66e06f220ce6318d9f72e3112912da7dc4c45

Author: Simon Peyton Jones <>
Date:   Thu Sep 29 16:06:17 2011 +0100

    Eliminate alleged optimisation that means we bogusly did NoGen
    Fixes Trac #5514.  The fix is simply to delete some code.

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

comment:4 Changed 5 years ago by dmwit

Resolution: fixed
Status: newclosed

Fix works perfectly.

comment:5 Changed 5 years ago by simonpj

Test Case: typecheck/should_compile/T5514
Note: See TracTickets for help on using tickets.