Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,868
    • Issues 4,868
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19384
Closed
Open
Created Feb 15, 2021 by Andreas Klebinger@AndreasKDeveloper

Pattern mach checking for Rationals seems to be broken.

Consider this code:

foo_small :: ()
foo_small = case 2e2 :: Rational of
  2e1 -> () -- redundant
  2e2 -> ()

-- Large exponents are handled differently so we have an extra check.
foo :: ()
foo = case 2e102 :: Rational of
  2e101 -> () -- redundant
  2e102 -> ()

-- Any literal of type T will desugar to the same value MkT.
-- Eg. (1.0 :: T) == MkT
data T = MkT deriving Eq
instance Num T where
instance Fractional T where
  fromRational _ = MkT

-- Large exponents are handled differently so we have an extra check.
bar :: ()
bar = case 2e102 :: T {- == MkT #-} of
  2e101 -> () -- not redundant, pattern evaluates to MkT
  2e102 -> () -- redundant, pattern also evaluates to MkT

baz :: ()
baz = case 2e1 :: T of
  2e1 -> () -- not redundant, pattern evaluates to MkT
  2e2 -> () -- redundant, pattern also evaluates to MkT

This currently (ghc-8.10, but also HEAD) only recognizes the last pattern match as redundant:

ghc T15646a.hs -O -Wall
[1 of 1] Compiling T15646a          ( T15646a.hs, T15646a.o ) [Optimisation flags changed]

T15646a.hs:34:3: warning: [-Woverlapping-patterns]
    Pattern match is redundant
    In a case alternative: 2e2 -> ...
   |
34 |   2e2 -> () -- redundant, pattern also evaluates to MkT
   |   ^^^^^^^^^
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking