Skip to content

-fdefer-out-of-scope-variables causes incorrect variable name in -Wunused-do-bind warning

Summary

When -fdefer-out-of-scope-variables is enabled, warnings caused by -Wunused-do-bind for the out-of-scope variable refer to an incorrect variable name.

Steps to reproduce

  1. Compile the following source code (notice the omitted import) using ghc -Wunused-do-bind -fdefer-out-of-scope-variables.
-- import Control.Concurrent (threadDelay)

main :: IO ()
main = do
    threadDelay 1
    return ()
  1. GHC prints the following output:
/Users/runesvendsen/code/tmp/ghc-bug-renamer/app/Main.hs:5:5: warning: [-Wdeferred-out-of-scope-variables]
    Variable not in scope: threadDelay :: Integer -> IO a0
  |
5 |     threadDelay 1
  |     ^^^^^^^^^^^

/Users/runesvendsen/code/tmp/ghc-bug-renamer/app/Main.hs:5:5: warning: [-Wunused-do-bind]
    A do-notation statement discarded a result of type ‘GHC.Types.Any’
    Suppress this warning by saying ‘_ <- threadDelay_a1bf 1’
  |
5 |     threadDelay 1
  |     ^^^^^^^^^^^^^

Notice the -Wunused-do-bind-warning referring to threadDelay_a1bf instead of threadDelay.

Expected behavior

The -Wunused-do-bind-warning should refer to threadDelay and not threadDelay_a1bf.

Environment

  • GHC version used: 8.8.1

Optional:

  • Operating System: OSX
  • System Architecture: x86_64

Source code for reproducing: Main.hs

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