Ticket #5117 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

OverloadedStrings induces overlapping pattern matches

Reported by: sciolizer Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.0.2
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Incorrect warning at compile-time Difficulty:
Test Case: deSugar/should_compile/T5117 Blocked By:
Blocking: Related Tickets:

Description

The OverloadedStrings? extension sometimes causes GHC to warn about overlapping pattern matches, when there are not overlapping pattern matches.

To reproduce, create the file BadWarning?.hs:

{-# LANGUAGE OverloadedStrings #-}
module BadWarning where

data MyString = MyString String

func (MyString "a") = undefined
func (MyString "bb") = undefined
func _ = undefined

Load the program with ghci -W BadWarning.hs, and ghci outputs

GHCi, version 7.0.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 1] Compiling BadWarning       ( BadWarning.hs, interpreted )

BadWarning.hs:6:1:
    Warning: Pattern match(es) are overlapped
             In an equation for `func': func (MyString "a") = ...
Ok, modules loaded: BadWarning.
*BadWarning>

The warning goes away if you remove the OverloadedStrings? extension. The warning also goes away if you change (MyString "bb") to (MyString "b") or (MyString "").

Change History

Changed 2 years ago by simonpj

  • status changed from new to closed
  • testcase set to deSugar/should_compile/T5117
  • resolution set to fixed

Thanks. An oversight in the tidying of literal patterns in the overlap checker. Fixed by

commit e79e580be5d3d7caed73dec9e5a72b244cd1cc39
Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Wed May 4 12:05:42 2011 +0100

    Fix Trac #5117: desugar literal patterns consistencly

 compiler/deSugar/Check.lhs    |   16 ++++++++--------
 compiler/deSugar/Match.lhs    |    2 +-
 compiler/deSugar/MatchLit.lhs |   14 ++++++++++----
 3 files changed, 19 insertions(+), 13 deletions(-)
Note: See TracTickets for help on using tickets.