[GHC] #15957: Provide warning for when RecordWildCards LHS {..} doesn't bind anything.

#15957: Provide warning for when RecordWildCards LHS {..} doesn't bind anything. -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: 8.6.3 Component: Compiler | Version: 8.6.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: -------------------------------------+------------------------------------- Given simple code like {{{#!haskell {-# LANGUAGE RecordWildCards #-} module M (foo) where data D = D { d1 :: Int, d2 :: Int } foo :: D -> Int -> Int foo D{..} x = x + 5 }}} There is no way that I know of to get GHC to warn us that the {{{ D{..} }}} in {{{foo}}} is not binding anything at all. This is very common after refactoring (perhaps {{{foo}}} looked like {{{foo D{..} x = x + d1 + 5}}} before) and would be great to be able to get a warning about. Of course it's not _dead_ code as it still forces {{{D}}} to WHNF but if we're using {{{RecordWildCards}}} syntax then it's probably not what we were going for. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15957 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15957: Provide warning for when RecordWildCards LHS {..} doesn't bind anything. -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.3 Component: Compiler | Version: 8.6.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 carter): If you compile will wall you don’t get an unused variable warning? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15957#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15957: Provide warning for when RecordWildCards LHS {..} doesn't bind anything. -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: 8.6.3 Component: Compiler | Version: 8.6.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 pacak):
If you compile with -wall you don’t get an unused variable warning?
No. {{{ % ghc -Weverything foo.hs ~ [1 of 1] Compiling M ( foo.hs, foo.o ) foo.hs:1:1: warning: [-Wimplicit-prelude] Module `Prelude' implicitly imported | 1 | {-# LANGUAGE RecordWildCards #-} | ^ <no location info>: warning: [-Wsafe] ‘M’ has been inferred as safe! }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15957#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15957: Provide warning for when RecordWildCards LHS {..} doesn't bind anything. -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.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 Fuuzetsu): To be clear, the behaviour we would like to see is a warning whenever the {..} adds no new used bindings into the environment. {{{#!haskell data P = P { x :: Int, y :: Int } f1 P{..} = 1 + 3 -- nothing bound is used f2 P{x, ..} = x + 3 -- y bound but not used f3 P{x, y, ..} = x + y -- no bindings left, i.e. no new useful bindings introduced g1 P{..} = x + 3 -- x from .. is used g2 P{x, ..} = x + y -- y from .. is used, even if it's in a weird style }}} f1, f2 and f3 should warn, g1 and g2 should not. I actually gave this a go myself but the way it was programmed was a bit too much for me for a quick hack. The way it is done now is that {{{..}}} is expanded into the bindings and those bindings are tagged with "don't warn if unusued" flag. Instead it should warn, but only if none of the {{{..}}}-bound names is used. Depending on how it's done, we should be careful to produce only a single warning &c. I imagine any solution is not too hard for anyone used to the codebase. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15957#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15957: Provide warning for when RecordWildCards LHS {..} doesn't bind anything. -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.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 Fuuzetsu): We (Tsuru Capital) have decided to offer a bounty for fixing this ticket. Please see https://www.reddit.com/r/haskell/comments/apavqf/experiment_ghc_bug_bounty/ if interested. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15957#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15957: Provide warning for when RecordWildCards LHS {..} doesn't bind anything. -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.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 mpickering): I have put a patch up which implements these flags. https://gitlab.haskell.org/ghc/ghc/merge_requests/346 Waiting for CI to run now to see if I missed anything. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15957#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15957: Provide warning for when RecordWildCards LHS {..} doesn't bind anything. -------------------------------------+------------------------------------- Reporter: Fuuzetsu | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: 8.10.1 Component: Compiler | Version: 8.6.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | rename/should_compile/T15957, | rename/should_fail/T15957_Fail Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | https://gitlab.haskell.org/ghc/ghc/merge_requests/346 -------------------------------------+------------------------------------- Changes (by RyanGlScott): * testcase: => rename/should_compile/T15957, rename/should_fail/T15957_Fail * status: new => closed * differential: => https://gitlab.haskell.org/ghc/ghc/merge_requests/346 * resolution: => fixed * milestone: => 8.10.1 Comment: Landed in [https://gitlab.haskell.org/ghc/ghc/commit/19626218566ea709b5f6f287d3c296b0c4... 19626218566ea709b5f6f287d3c296b0c4021de2]. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15957#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC