Skip to content

Inconsistent unused variable warnings

Summary

  1. Function-argument bound, let bound and where bound variables are treated inconsistently when it comes to unused variable warnings.
  2. Variables appearing on the RHS of a strict binding should be considered "used".

Steps to reproduce

% cat test1.hs && /opt/ghc/bin/ghc-8.10.2 test1.hs
{-# LANGUAGE BangPatterns #-}

{-# OPTIONS_GHC -Wall #-}

module Foo where

foo :: a -> ()
foo a = let _ = undefined a b c
            b = ()
        in ()
  where c = ()

bar :: a -> ()
bar a = let !_ = undefined a b c
            b = ()
        in ()
  where c = ()
[1 of 1] Compiling Foo              ( test1.hs, test1.o )

test1.hs:9:13: warning: [-Wunused-local-binds]
    Defined but not used: b
  |
9 |             b = ()
  |             ^

test1.hs:15:13: warning: [-Wunused-local-binds]
    Defined but not used: b
   |
15 |             b = ()
   |             ^

Expected behavior

  1. For each function there should either be a warning for all of a, b and c or for none of them.
  2. I would also expect a strict binding to "use" all the variables on its RHS, even if it binds no variables.

Environment

8.10.2 from HVR's Ubuntu PPA

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