[project @ 2003-02-04 12:28:22 by simonpj]
authorsimonpj <unknown>
Tue, 4 Feb 2003 12:28:26 +0000 (12:28 +0000)
committersimonpj <unknown>
Tue, 4 Feb 2003 12:28:26 +0000 (12:28 +0000)
commit115f0fae2f782836550a9419f739fd29c09e4f1b
treefba3a1b8e57ce0694758aef3388f00d9282d8100
parent60beff5f890d5faae37f443a5822ae85ac72aaf5
[project @ 2003-02-04 12:28:22 by simonpj]
---------------------------------------------------
Important fix to the handling of class methods that
      mention their own class type variable
---------------------------------------------------

[NB: I'm not 100% certain that this commit is independent of the
     Template-Haskell-related commit I'm doing at the same time.
     I've tried to separate them but may not have succeeded totally.]

This bug gives utterly bogus (detected by Core Lint) programs.
Isaac Jones discovered it.  Here's an example, now enshrined as tc165.

    class C a where
f :: (Eq a) => a

    instance C () where
f = f

The instance decl was translated as

    dfC() = MkC (let f = \dEq -> f in f)

which is utterly wrong.  Reason: the 'f' on the left was being treated
as an available Inst, but it doesn't obey INVARIANT 2 for Insts, which
is that they are applied to all their dictionaries.  (See the data type
decl for Inst.)

Solution: don't include such class methods in the available Insts.
ghc/compiler/typecheck/Inst.lhs
ghc/compiler/typecheck/TcClassDcl.lhs
ghc/compiler/typecheck/TcInstDcls.lhs
ghc/compiler/typecheck/TcMonoType.lhs