Opened 2 years ago

Closed 2 years ago

#13651 closed bug (fixed)

Invalid redundant pattern matches with -XTypeFamilyDependencies

Reported by: crockeea Owned by:
Priority: normal Milestone: 8.2.1
Component: Compiler Version: 8.0.2
Keywords: InjectiveFamilies Cc: Iceland_jack
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect error/warning at compile-time Test Case: typecheck/should_compile/T13651
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The following code triggers a warning about a redundant pattern match for foo:

{-# LANGUAGE TypeFamilies, TypeFamilyDependencies #-}

type family F r s = f | f -> r s

type instance F (Bar h (Foo r)) (Bar h (Foo s)) = Bar h (Bar r s)

data Bar s b
data Foo a

foo :: (F cr cu ~ Bar h (Bar r u), 
        F cu cs ~ Bar (Foo h) (Bar u s))
    => Bar h (Bar r u) -> Bar (Foo h) (Bar u s) -> Foo (cr -> cs)
foo = undefined
warning: [-Woverlapping-patterns]
    Pattern match is redundant
    In an equation for ‘foo’: foo = ..

This warning seems invalid to me: I'm not sure how a single definition could constitute a redundant pattern match. Moreover, if I try to address the warning by removing the "redundant" pattern, the code (of course) fails to compile because there is no accompanying binding for the signature of foo.

Change History (7)

comment:1 Changed 2 years ago by RyanGlScott

This appears to be fixed in GHC 8.2.1, although I don't recall what commit fixed it.

comment:2 Changed 2 years ago by Iceland_jack

Cc: Iceland_jack added

comment:3 Changed 2 years ago by simonpj

Terrific -- worth a regression test?

comment:4 Changed 2 years ago by mpickering

I think it was this commit that changed this behaviour.

comment:5 Changed 2 years ago by RyanGlScott

As it turns out, that's not the full story. The first commit in which the program in this ticket compiled without warnings was eb55ec2941239dee05afc6be818b129efe51660e (Refactor functional dependencies a bit).

Commit adb565aa74582969bbcc3b411d6d518b1c76c3cf, on the other hand, did squash needless pattern-match warnings in some other, similar programs, such as this one:

{-# LANGUAGE TypeFamilies #-}
module Bug2 where

foo :: Int ~ Bool => a -> a
foo x = x

comment:6 Changed 2 years ago by Ryan Scott <…>

In ed0c7f8b/ghc:

Add regression test for #13651

Commit eb55ec2941239dee05afc6be818b129efe51660e ended up fixing #13651, so
let's add a regression test for it.

comment:7 Changed 2 years ago by RyanGlScott

Milestone: 8.2.1
Resolution: fixed
Status: newclosed
Test Case: typecheck/should_compile/T13651
Note: See TracTickets for help on using tickets.