Skip to content

GHCi accepts invalid programs when recompiling

This ticket may or may not be a duplicate of #9729, but I ran into it again in a different context, so I'm reporting it. My GHC version is 7.10.2.20151030. The example is as minimal as I could make it.

File Bar.hs

{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}

module Bar where

class Bar a b where
  (*^) :: a -> b -> b

File Foo.hs

{-# LANGUAGE MultiParamTypeClasses #-}

module Foo where

import Bar
import GHC.Prim

newtype Foo fp = Foo [fp]

instance {-# OVERLAPS #-}
  Bar (Foo fp) [fp]

File Main.hs

{-# LANGUAGE MultiParamTypeClasses #-}

import Foo
import Bar

newtype LW a = LW [a]

instance Bar (Foo fp) (LW fp) where
  r *^ (LW xs) = LW $ r *^ xs

If I start GHCi with ghci Main, everything compiles as it should. Then I remove the {-# OVERLAPS #-} pragma in Foo.hs, which should break Main.hs. But GHCi happily recompiles with :r.

A couple of notes: *with* the pragma, :i Bar gives the instances

instance Bar (Foo fp) (LW fp) -- Defined at Main.hs:8:10
instance Bar a b => Bar a [b] -- Defined at Bar.hs:8:10
instance [overlap ok] Bar (Foo fp) [fp] -- Defined at Foo.hs:22:3

while after (successfully, but incorrectly) recompiling without the pragma, I get the instances

instance Bar (Foo fp) (LW fp) -- Defined at Main.hs:8:10
instance Bar a b => Bar a [b] -- Defined at Bar.hs:8:10
instance Bar (Foo fp) [fp] -- Defined at Foo.hs:22:3

(i.e., without the [overlap ok]).

Another strange thing is that the bug is only triggered if I import specific (superfluous) modules in Foo.hs. For example, if I replace GHC.Prim with Control.Monad or Data.Maybe, the bug is not triggered (i.e., GHCi correctly detects when I remove the pragma).

Trac metadata
Trac field Value
Version 7.10.2-rc2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information