[GHC] #11680: Out-of-scope suggestion given for an out-of-scope variable when using TH
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1-rc2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- With GHC 8.x, compiling {{{#!hs {-# LANGUAGE TemplateHaskell #-} module A where import Language.Haskell.TH sep :: Q [Dec] sep = [d| x = () |] }}} and {{{#!hs {-# LANGUAGE TemplateHaskell #-} module B where import A f :: Int f = foo $(sep) foo :: Int foo = 3 }}} produces {{{ $ ghc-HEAD/inplace/bin/ghc-stage2 --version The Glorious Glasgow Haskell Compilation System, version 8.1.20160303 $ ghc-HEAD/inplace/bin/ghc-stage2 B.hs [1 of 2] Compiling A ( A.hs, A.o ) [2 of 2] Compiling B ( B.hs, B.o ) B.hs:8:5: error: • Variable not in scope: foo :: Int • Perhaps you meant ‘foo’ (line 13) }}} The problem is that when the typechecker constructs the suggestion, it uses the currently available `GlobalRdrEnv` rather than the one in existence when the renamer determined that `foo` is unbound. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by goldfire): * component: Compiler => Template Haskell Comment: Yes, that is quite silly. Since it seems you have poked around in the code to understand what is going on here, might you submit a patch for this? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Ideally -- if this mistake can be easily detected -- some information about how top-level splices break up a file would be helpful. This (documented) trap catches many. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jme): Sure, I can submit a patch. And it shouldn't be too difficult to include TH-specific details in the error message. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: jme Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by jme): * owner: => jme -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: jme Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): Yay! Thanks! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: jme Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2000 Wiki Page: | -------------------------------------+------------------------------------- Changes (by jme): * status: new => patch * differential: => Phab:D2000 Comment: I've submitted a patch (Phab:D2000). I'm still not completely happy with the form of the new error message, since it states where an exact match to an out-of-scope variable is '''not''' in scope: {{{ T11680.hs:37:7: error: • Variable not in scope: bar :: () • ‘bar’ (line 82) is not in scope before the splice on lines 78-80 Perhaps you meant one of these: ‘bat’ (line 40), ‘baz’ (line 43) }}} But specifying where it '''is''' in scope would have been far wordier. If you think the extra detail would be more helpful to users, though, I'm happy to change it. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: jme Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2000 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Hmm, I'm a bit on the fence as to whether we should include this in 8.0.1 given the size of the diff. Conceptually it seems relatively low-risk, but still merging such changes so late in the game makes me a bit nervous. goldfire and jme, what do you think? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: jme Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2000 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"470d4d5b8e7cbcc176b1f3ac26ce0d95acd35a78/ghc" 470d4d5b/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="470d4d5b8e7cbcc176b1f3ac26ce0d95acd35a78" Fix suggestions for unbound variables (#11680) When the typechecker generates the error message for an out-of-scope variable, it now uses the GlobalRdrEnv with respect to which the variable is unbound, not the GlobalRdrEnv which is available at the time the error is reported. Doing so ensures we do not provide suggestions which themselves are out-of-scope (because they are bound in a later inter-splice group). Nonetheless, we do note in the error message if an unambiguous, exact match to the out-of-scope variable is found in a later inter-splice group, and we specify where that match is not in scope. Test Plan: ./validate Reviewers: goldfire, austin, bgamari Reviewed By: goldfire Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2000 GHC Trac Issues: #11680 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: jme Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.0.1-rc2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2000 Wiki Page: | -------------------------------------+------------------------------------- Comment (by jme): Replying to [comment:7 bgamari]: I think waiting until 8.0.2 to include it is fine. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11680: Out-of-scope suggestion given for an out-of-scope variable when using TH -------------------------------------+------------------------------------- Reporter: jme | Owner: jme Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Template Haskell | Version: 8.0.1-rc2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2000 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed * milestone: => 8.0.1 Comment: Too late; already merged as f93c9517a2c6e158e4a5c5bc7a3d3f88cb4ed119. Thanks jme! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11680#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC