Opened 3 years ago

Closed 3 years ago

Last modified 3 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 Difficulty:
Test Case: typecheck/should_compile/T5514 Blocked By:
Blocking: Related Tickets:

Description

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:

test.hs:6:10:
    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 3 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 3 years ago by simonpj

I'm on it.

comment:3 Changed 3 years ago by simonpj@…

commit 9aa66e06f220ce6318d9f72e3112912da7dc4c45

Author: Simon Peyton Jones <simonpj@microsoft.com>
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 3 years ago by dmwit

  • Resolution set to fixed
  • Status changed from new to closed

Fix works perfectly.

comment:5 Changed 3 years ago by simonpj

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