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,869
    • Issues 4,869
    • 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
  • #21662
Closed
Open
Created May 27, 2022 by sheaf@sheafMaintainer

Pattern-match coverage checker mishandles dictionary arguments

It seems that the pattern match coverage checker does not correctly handle dictionary arguments, as evidenced by the following:

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeApplications #-}

{-# OPTIONS_GHC -Wincomplete-patterns #-}

import GHC.TypeNats (Nat, KnownNat)

pred1 :: forall (n :: Nat). Int -> Bool
pred1 i = i > 0

pred2 :: forall (n :: Nat). KnownNat n => Int -> Bool
pred2 i = i > 0

foo1 :: Int -> Int
foo1 (pred1 @12 -> True) = 0
foo1 (pred1 @12 -> False) = 0

foo2 :: Int -> Int
foo2 (pred2 @12 -> True) = 0
foo2 (pred2 @12 -> False) = 0

foo1 correctly does not report any pattern match warnings, however foo2 does, because of the dictionary argument:

Pattern match(es) are non-exhaustive
In an equation for ‘foo2’: Patterns not matched: _ :: Int
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking