Skip to content

Non-exhaustive patern matches in function declarations generated by QuasiQuotes don't report the warning

Summary

When a function declaration is generated by a QuasiQuotes expression, and has an incomplete pattern match ghc doesn't give the warning.

Steps to reproduce

Foo.hs

module Foo where

import Language.Haskell.TH
import Language.Haskell.TH.Quote

foo :: QuasiQuoter
foo = QuasiQuoter { quoteExp  = undefined,
                    quotePat  = undefined,
                    quoteType = undefined,
                    quoteDec  = fooDec }

fooDec :: String -> Q [Dec]
fooDec fNameStr =  do
  let fName = mkName fNameStr
  let xName   = mkName "x"
  Just justName <- lookupValueName "Just"
  return [
    FunD fName [
      Clause [ConP justName [VarP xName ]] (NormalB $ LitE $ IntegerL 0) []
               ]
          ]

Bar.hs

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}

import Foo

bar :: Maybe Int -> Int
[foo|bar|]

main :: IO ()
main = do
  print $ bar (Just 1)
  print $ bar Nothing

Expected behavior

running ghc -Wall Bar.hs Should produce 2 errors:

  1. Defined but not used: 'x' ...
  2. Pattern match(es) are non-exhaustive In an equation for ‘bar’: Patterns not matched: Nothing

Environment

  • GHC version used: 8.8.4

Optional:

  • Operating System: Artix Linux
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information