[GHC] #13646: strict patterns with no bindings (e.g. `let !() = ...`) trigger -Wunused-pattern-binds

#13646: strict patterns with no bindings (e.g. `let !() = ...`) trigger -Wunused- pattern-binds -------------------------------------+------------------------------------- Reporter: exphp | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.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: -------------------------------------+------------------------------------- In each of the following programs, a bang pattern is used to force evaluation of a bottom, the intent being to perform fail-fast error checking. Unfortunately, however, they also generate `-Wunused-pattern- binds`. {{{#!hs {-# OPTIONS_GHC -Wall #-} {-# LANGUAGE BangPatterns #-} main :: IO () main = do let !Nothing = Just () pure () }}} {{{#!hs {-# OPTIONS_GHC -Wall #-} {-# LANGUAGE BangPatterns #-} import Control.Exception main :: IO () main = do let !() = assert False () pure () }}} {{{ src/Lib.hs:6:9: warning: [-Wunused-pattern-binds] This pattern-binding binds no variables: !Nothing = Just () Linking src/Lib ... Lib: src/Lib.hs:6:9-26: Irrefutable pattern failed for pattern Nothing -------------------- src/Lib.hs:8:9: warning: [-Wunused-pattern-binds] This pattern-binding binds no variables: !() = assert False () Linking src/Lib ... Lib: Assertion failed CallStack (from HasCallStack): assert, called at src/Lib.hs:8:15 in main:Main }}} For clarity, non-monadic `let ... in` patterns are also affected; I only gloss over them because there tends to be other equally ergonomic alternatives in such cases. I found this #9127 (ticket), where a patch was accepted to allow wildcards of the form `!_`. However, `!_` is unsatisfactory and perhaps even dangerous for such usage, as it does not constrain the type in any manner. In particular, there is nothing to prevent somebody from writing {{{#!hs main = do let !_ = assert someCondition -- (missing an argument) pure () }}} which //is// in fact useless. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13646 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13646: strict patterns with no bindings (e.g. `let !() = ...`) trigger -Wunused- pattern-binds -------------------------------------+------------------------------------- Reporter: exphp | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Yes I see the point. Perhaps we should suppress this warning if the pattern has an outmost bang. Does anyone object? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13646#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13646: strict patterns with no bindings (e.g. `let !() = ...`) trigger -Wunused- pattern-binds -------------------------------------+------------------------------------- Reporter: exphp | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): No objection here. I think exphp's point about the assertion with a missing function is quite interesting in itself. Simon, do you think it would be possible to implement a warning when someone applies a bang pattern, `seq`, or `seq#` to something known to have a function type? That seems almost always the wrong thing. It's also bad to force something that will take a dictionary argument, but that seems potentially harder to detect conservatively. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13646#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13646: strict patterns with no bindings (e.g. `let !() = ...`) trigger -Wunused- pattern-binds -------------------------------------+------------------------------------- Reporter: exphp | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by exphp): I am conflicted on dfeuer's suggestion, since functions too can be bottom: {{{#!hs bottomsUp :: a -> a bottomsUp = error "oops" ... let !_ = bottomsUp -- error: Lib: oops }}} So generating warnings on this would be a somewhat opinionated change. Yet at the same time, it is an opinion I perhaps agree with; such code is playing with fire! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13646#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13646: strict patterns with no bindings (e.g. `let !() = ...`) trigger -Wunused-
pattern-binds
-------------------------------------+-------------------------------------
Reporter: exphp | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#13646: strict patterns with no bindings (e.g. `let !() = ...`) trigger -Wunused- pattern-binds -------------------------------------+------------------------------------- Reporter: exphp | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | rename/should_compile/T13646 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * testcase: => rename/should_compile/T13646 * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13646#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC