Ticket #2395 (closed bug: fixed)

Opened 5 years ago

Last modified 3 years ago

"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 Difficulty: Unknown
Test Case: deSugar/should_compile/T2395 Blocked By:
Blocking: Related Tickets:

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

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

Change History

Changed 5 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 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").

Changed 5 years ago by NeilMitchell

  • cc ndmitchell@… added
  • os changed from Linux to Unknown/Multiple
  • architecture changed from x86 to Unknown/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".

Changed 4 years ago by ganesh

  • cc ganesh@… added

Changed 4 years ago by igel

  • cc deduktionstheorem@… added

Changed 4 years ago by BenMoseley

  • cc ben@… added

Changed 4 years ago by mafo

  • cc fontaine@… added

Changed 4 years ago by ajd

  • cc alexander.dunlap@… added

Changed 4 years ago by igloo

  • milestone changed from 6.10 branch to 6.12.1

Changed 4 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?

Changed 4 years ago by igloo

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

Changed 4 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.

Changed 4 years ago by andrewbirkett

  • cc andy@… added

Changed 4 years ago by ajd

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

Changed 4 years ago by ajd

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

Changed 4 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.

Changed 4 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Thanks, patches applied.

Changed 4 years ago by simonpj

  • testcase set to 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

Changed 3 years ago by guest

  • cc changed from ben@moseley.name, ndmitchell@gmail.com, ganesh@earth.li, deduktionstheorem@web.de, fontaine@cs.uni-duesseldorf.de, alexander.dunlap@gmail.com, sveina@gmail.com, andy@nobugs.org to ben@moseley.name, ndmitchell@gmail.com, ganesh@earth.li, deduktionstheorem@web.de, fontaine@cs.uni-duesseldorf.de, alexander.dunlap@gmail.com, sveina@gmail.com, andy@nobugs.org
  • failure set to None/Unknown

Changed 3 years ago by guest

  • failure changed from None/Unknown to Incorrect warning at compile-time
Note: See TracTickets for help on using tickets.