Opened 9 years ago

Closed 8 years ago

Last modified 7 years ago

#2395 closed bug (fixed)

"Pattern match(es) are overlapped" warning with a single view pattern (ghc 6.9.20080606)

Reported by: rwbarton Owned by: igloo
Priority: normal Milestone: 6.12.1
Component: Compiler Version: 6.9
Keywords: Cc: ben@…, ndmitchell@…, ganesh@…, deduktionstheorem@…, fontaine@…, alexander.dunlap@…, sveina@…, andy@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case: deSugar/should_compile/T2395
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Compiling the program

{-# LANGUAGE ViewPatterns #-}

main = print $ case 6 of
                 (even -> True) -> 4

yields the warning message

view.hs:3:15:
    Warning: Pattern match(es) are overlapped
             In a case alternative: ((even -> True)) -> ...

I haven't used view patterns before... but surely a single pattern can't overlap anything, can it?

Attachments (2)

fix-2395.dpatch (32.4 KB) - added by ajd 8 years ago.
Patch that fixes the problem by turning off the checker entirely for any equation that has view patterns
test-2395.dpatch (8.0 KB) - added by ajd 8 years ago.
Regression test (not sure if I added the test correctly, but the meat is there)

Download all attachments as: .zip

Change History (19)

comment:1 Changed 9 years ago by igloo

difficulty: Unknown
Milestone: 6.10 branch

This is due to this case of check' in deSugar/Check.lhs:

-- FIXME: hack to get view patterns through for now
   | otherwise    = ([([],[])],emptyUniqSet)

(the emptyUniqSet means "the pattern is never used").

comment:2 Changed 8 years ago by NeilMitchell

Architecture: x86Unknown/Multiple
Cc: ndmitchell@… added
Operating System: LinuxUnknown/Multiple

If you use View Patterns, this is absolutely infuriating! In one project I use view patterns in 8 places, so the compilation output becomes so verbose I miss genuine errors. It's fine for view patterns to not participate in overlap/exhaustive checking, but it should do so by _not_ issuing loads of bogus warnings which cannot be worked around :-)

This bug seriously impacts on the usability of view patterns, which is a real shame because I'm finding them to be a very useful practical feature. I'd argue for this bug being "major" rather than "minor".

comment:3 Changed 8 years ago by ganesh

Cc: ganesh@… added

comment:4 Changed 8 years ago by igel

Cc: deduktionstheorem@… added

comment:5 Changed 8 years ago by BenMoseley

Cc: ben@… added

comment:6 Changed 8 years ago by mafo

Cc: fontaine@… added

comment:7 Changed 8 years ago by ajd

Cc: alexander.dunlap@… added

comment:8 Changed 8 years ago by igloo

Milestone: 6.10 branch6.12.1

comment:9 Changed 8 years ago by Baughn

Cc: sveina@… added

This bug makes view patterns absolutely impossible to use.

I accept that fixing it could take some work, but can we at least suppress the warning in 6.10.4? Add an option for that, perhaps?

comment:10 Changed 8 years ago by igloo

You can turn the warning off with -fno-warn-overlapping-patterns.

comment:11 Changed 8 years ago by Baughn

I could, but then I lose all the overlap warnings, and I'd really like to keep them around. I don't always use view patterns.

comment:12 Changed 8 years ago by andrewbirkett

Cc: andy@… added

Changed 8 years ago by ajd

Attachment: fix-2395.dpatch added

Patch that fixes the problem by turning off the checker entirely for any equation that has view patterns

Changed 8 years ago by ajd

Attachment: test-2395.dpatch added

Regression test (not sure if I added the test correctly, but the meat is there)

comment:13 Changed 8 years ago by ajd

Owner: set to igloo

I've attached a patch to GHC and a patch to the testsuite that ought to fix the problem by turning off the checker for any definition that includes view patterns.

comment:14 Changed 8 years ago by igloo

Resolution: fixed
Status: newclosed

Thanks, patches applied.

comment:15 Changed 8 years ago by simonpj

Test Case: deSugar/should_compile/T2395

I've improved the fix with

Mon Aug 10 15:11:58 BST 2009  simonpj@microsoft.com
  * Improve the recent changes to overlap-checking for view patters
  
  The previous patch simply gave up for view patterns; this version
  instead treats them like n+k patterns and gives signficantly better
  results.
  
  Less code, too.
  

    M ./compiler/deSugar/Check.lhs -85 +101
    M ./compiler/hsSyn/HsPat.lhs -29 +1

and added a test case

Simon

comment:16 Changed 7 years ago by guest

Type of failure: None/Unknown

comment:17 Changed 7 years ago by guest

Type of failure: None/UnknownIncorrect warning at compile-time
Note: See TracTickets for help on using tickets.