Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • 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,823
    • Issues 4,823
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 447
    • Merge requests 447
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17416

Closed
Open
Created Oct 29, 2019 by sheaf@sheafMaintainer

Missing overlapping pattern warning for pattern with required constraint

Adding a required constraint to a pattern affects overlap checking:

{-# OPTIONS_GHC -Woverlapping-patterns -Wincomplete-patterns #-}
{-# LANGUAGE FlexibleContexts, PatternSynonyms #-} 

class C a where

pattern P1 :: C Int => Int
pattern P1 = 1

test :: C Int => Int -> Int
test i = case i of
  P1 -> 3
  P1 -> 7
  _  -> 11

This causes no warnings. Removing the required constraint to the pattern signature of P1 reinstates the expected warning:

    Pattern match is redundant
    In a case alternative: P1 -> ...

Note that this is not limited to pattern synonyms, as can be seen by inlining the pattern signature.
Note also that completeness checking is not affected (as can be seen by removing the catch-all case).

I saw a few tickets concerning overlap checking in particular in the context of insoluble constraints (e.g. #13766), but in this case it seems a shame to lose overlap checking. Is there some option I could switch on to enforce overlap checks?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking