Opened 12 years ago

Closed 4 years ago

#1307 closed bug (duplicate)

Warning refers to code not in the source

Reported by: guest Owned by:
Priority: lowest Milestone:
Component: Compiler Version: 6.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Here's some source:

toXML = toXMLEx (Just . cap)
  where cap ('_':cs) = cap cs
        cap (c:cs) = toUpper c : cs
        cap "" = ""

And here's a warning that refers to notElem which I've not used:

../Gmag/Paradise/Addins/XML/Prim.hs:47:8:
    Warning: Pattern match(es) are non-exhaustive
             In the definition of `cap':
                 Patterns not matched: #x with #x `notElem` [""#]

-- Lennart

Change History (9)

comment:1 Changed 12 years ago by simonmar

Milestone: _|_
Priority: normallowest

This belongs to the class of bugs related to our non-exhaustive pattern checking, which is old and flaky. See for example #29. One day this will get rewritten, for now I'm lowering the prio.

comment:2 Changed 12 years ago by igloo

The warning referring to notElem isn't incorrect, though; it's just specifying which cases (it thinks) aren't handled.

For example, if you compile

cap :: String -> String
cap ('_':cs) = cap cs
cap ('!':cs) = cap cs
cap "" = ""

with -Wall then you get the warning

Warning: Pattern match(es) are non-exhaustive
         In the definition of `cap':
             Patterns not matched: (GHC.Base.C# #x) : _ with #x `notElem` ['_', '!']

i.e. it is telling you that you have not handled the case (x:xs) where x is not one of ['_', '!'].

It does seem odd that it thinks that you have missing cases in your function, though. My HEAD, which claims to be 6.7.20070420, doesn't generate that warning.

comment:3 Changed 12 years ago by simonpj

There are three things going on here:

  • Whether a warning is generated at all for this particular program. It should not be; and Ian says he can't reproduce it. Perhpas a glitch?
  • How to report missing patterns. Lennart, how would you like GHC to report "you have not covered the case where the head of the input list is '!' or '_'"? In general, of course. Maybe we should replace the notElem with "is not one of".
  • Another bad thing about the current report is that it exposes the representation of characters. This is structural: the overlap checker first expands character patterns and only then checks for overlap. It's easily fixed -- when someone re-engineers the overlap checker.

Incidentally, there's a new paper out about overlap warnings "Warnings for pattern matching" by Luc Maranget, JFP 17(3), May 07. All ready for someone to implement.

Simon

comment:4 Changed 12 years ago by simonmar

See Task #595

comment:5 Changed 11 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:6 Changed 7 years ago by morabbin

Type of failure: None/Unknown

Seems like its covered by #595 (this one is about better errors/warnings only).

comment:7 Changed 7 years ago by simonmar

We should keep this around, if someone ever does #595 they'll want to fix this at the same time.

comment:8 Changed 4 years ago by thomie

Operating System: WindowsUnknown/Multiple

comment:9 Changed 4 years ago by thomie

Resolution: duplicate
Status: newclosed

Because the existence of duplicate tickets makes doing a BugSweep of the bug tracker more cumbersome, I'm closing these tickets as duplicate. Don't worry, they're still listed on PatternMatchCheck, and will hopefully all be addressed by the work on #595 ("Overhaul GHC's overlapping/non-exhaustive pattern checking").

Note: See TracTickets for help on using tickets.