Opened 5 years ago

Closed 4 years ago

Last modified 2 years ago

#5951 closed bug (fixed)

Panic on Malformed instance A => B => C

Reported by: br1 Owned by:
Priority: normal Milestone: 7.6.1
Component: Compiler Version: 7.4.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: x86
Type of failure: Compile-time crash Test Case: rename/should_fail/T5951
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:



A => B => C where

foo = undefined

Change History (12)

comment:1 Changed 5 years ago by pcapriotti

  • difficulty set to Unknown
  • Milestone set to 7.6.1

comment:2 Changed 4 years ago by simonpj@…

commit dd847cb899275adb5f3250e1447198cb61875bea

Author: Simon Peyton Jones <>
Date:   Fri Mar 30 12:43:45 2012 +0100

    Don't crash if there's a malformed instance!
    Fixes Trac #5951

 compiler/rename/RnSource.lhs |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

comment:3 Changed 4 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to rename/should_fail/T5951

comment:4 Changed 4 years ago by dag

I ran into this by leaving out the fat arrow completely; does the fix solve that case as well?

comment:5 Changed 4 years ago by simonpj

I don't know without a concrete example. If you suggest a program I guess I can test it with HEAD? Or maybe you can too?


comment:6 Changed 4 years ago by dag

I couldn't reproduce the issue without equality constraints, so those may be necessary:

{-# LANGUAGE FlexibleInstances, TypeFamilies, MultiParamTypeClasses #-}

import qualified Data.Set as Set

class IsList a b c where
    fromList :: [b] -> a c

-- Note the missing => before IsList here
instance (Ord b, b ~ c) IsList Set.Set b c where
    fromList = Set.fromList
*** Exception: compiler/rename/RnSource.lhs:429:14-81: Irrefutable pattern failed for pattern Data.Maybe.Just (inst_tyvars,
                                                        SrcLoc.L _ cls,

comment:7 Changed 4 years ago by dag

Actually, I suspect that it's the comma and not the equality constraint, and that multiple contexts would work as well. Otherwise, it's interpreted to be an instance declaration for the Ord class itself, and the error is that fromList is not a visible member.

comment:8 Changed 4 years ago by simonpj

Happily HEAD says

    Malformed instance: (Ord b, b ~ c) IsList Set.Set b c

on your example. So yes, I think this is fixed.

comment:9 Changed 4 years ago by guest

  • Architecture changed from Unknown/Multiple to x86
  • Version changed from 7.4.1 to 7.4.2


I get the same error on GHC 7.4.2 with the following (slightly different) example:

instance ExprCoercion a -> b where
    fromExpr (FunctionExpr fn) = fn
    toExpr fn = FunctionExpr $ \expr -> toExpr $ fn (fromExpr expr)
*** Exception: compiler/rename/RnSource.lhs:430:14-81: Irrefutable pattern failed for pattern Data.Maybe.Just (inst_tyvars,
                                                        SrcLoc.L _ cls,
Last edited 2 years ago by hvr (previous) (diff)

comment:10 Changed 4 years ago by simonpj

It's fixed in HEAD, but on in 7.4.2.


comment:11 Changed 4 years ago by boris

I ran into this issue with -> arrows in GHC 7.4.1. Could you please check this code in HEAD?

-- no language extensions
class Clazz a where
  func :: a -> String

instance Clazz a -> Clazz (Bool -> a) where
  func = undefined

comment:12 Changed 4 years ago by simonpj

Yes, it's fine in HEAD

simonpj@cam-05-unx:~/tmp$ ghc-stage2 -c Foo.hs

Foo.hs:9:10: Malformed instance: Clazz a -> Clazz (Bool -> a)
Note: See TracTickets for help on using tickets.