[GHC] #14805: Allow disabling warnings on a per-block of code basis

GHC ghc-devs at haskell.org
Tue Feb 13 18:47:10 UTC 2018


#14805: Allow disabling warnings on a per-block of code basis
-------------------------------------+-------------------------------------
           Reporter:  MaxGabriel     |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.2.2
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Haskell developers frequently want to disable a warning, but not for their
 whole project. Right now the only way to do that is on a per-file basis.
 This isn't ideal, because it's a pretty broad brush for what is often a
 warning you only want to disable in one place. The way other compilers
 solve this is by allowing you to ignore warnings only between two lines in
 the code. Here's Clang and GCC:

 {{{
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunused-variable"

 int a;

 #pragma clang diagnostic pop
 }}}

 {{{
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wunused-result"
     write(foo, bar, baz);
 #pragma GCC diagnostic pop
 }}}

 Examples of warnings people may want to ignore only in a certain location:

 In
 [https://github.com/yesodweb/yesod/blob/f2b651b69537985c5a2ca378018fd50537c3454b
 /yesod-core/Yesod/Core.hs#L5 yesod-core/yesod/Core.hs], deprecation
 warnings are disabled for the whole file, but it's not clear what
 deprecations are trying to be avoided. It's possible that code is no
 longer relevant.

 The tests for the `yesod-test` package test a function that yesod-test has
 deprecated, but still wants to test. Because of this,
 [https://github.com/yesodweb/yesod/blob/f2b651b69537985c5a2ca378018fd50537c3454b
 /yesod-test/test/main.hs#L1-L2 it ignores all deprecation warnings], when
 it could be only ignoring them for a few lines.

 It's pretty easy to find examples of this; just search a repo for `{-#
 OPTIONS_GHC -fno` and you'll probably find cases where warnings are
 disabled in a more broad way than is necessary.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14805>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list