Opened 10 years ago

Last modified 17 months ago

#322 new bug (None)

fromInteger-related pattern match overlap warnings

Reported by: ashley-y Owned by: simonpj
Priority: normal Milestone:
Component: Compiler Version: 6.4
Keywords: warnings Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: ds060
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description (last modified by igloo)

The compiler incorrectly gives "Warning: Pattern match(es) are 
overlapped" for this file:

{-# OPTIONS -Werror #-}

module Buggy where

	instance (Num a) => Num (Maybe a) where
		(Just a) + (Just b) = Just (a + b)
		_ + _ = Nothing
		(Just a) - (Just b) = Just (a - b)
		_ - _ = Nothing
		(Just a) * (Just b) = Just (a * b)
		_ * _ = Nothing
		negate (Just a) = Just (negate a)
		negate _ = Nothing
		abs (Just a) = Just (abs a)
		abs _ = Nothing
		signum (Just a) = Just (signum a)
		signum _ = Nothing
		fromInteger = Just . fromInteger

	f :: Maybe Int -> Int
	f 1 = 1
	f Nothing = 2
	f _ = 3

Change History (10)

comment:1 Changed 9 years ago by nobody

Logged In: NO 

If we define the first line as:

f (Just 1) = 1

there is no problem. 

comment:2 Changed 9 years ago by igloo

  • Architecture set to Unknown
  • Description modified (diff)
  • difficulty set to Unknown
  • Keywords warnings added
  • Milestone set to _|_
  • Operating System set to Unknown
  • Test Case set to ds060

comment:3 Changed 8 years ago by simonmar

See #595

comment:4 Changed 7 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:5 Changed 7 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple

comment:6 Changed 5 years ago by marcotmarcot

  • Type of failure set to None/Unknown

I'm thinking about this bug, and the only way I can see to avoid it, is by knowing in compile-time, that is, when the compiler checks if the Patterns are complete, how the value (1 :: Integer) will be converted to (1 :: Maybe Int). This is defined in "fromInteger = Just . fromInteger", which is a user code. So the user code will have to be evaluated in compile time. Is this already done in any case? I don't think so, as this would create the possibility of the compilation not terminating.

comment:7 Changed 5 years ago by igloo

You can't make the warning perfect, but in cases where we are not sure we have 3 choices:

  • warn
  • don't warn
  • give a different warning, saying that we aren't sure (this warning could be en/disabled separately)

comment:8 Changed 21 months ago by monoidal

See also #8016

comment:9 Changed 17 months ago by Ian Lynagh <igloo@…>

In 50e451242b50bd57c5ad6268b97f6a480c24fe32/ghc:

Add test ds060 for trac #322 (bogus overlapping patterns warnings)

comment:10 Changed 17 months ago by Ian Lynagh <igloo@…>

In fef7a82c6897afb5196ca91a097c5d6b2462d4b7/ghc:

ds060 and ds061 are broken: trac #322, #851
Note: See TracTickets for help on using tickets.