[GHC] #11071: The "Not in scope" error is misleading
#11071: The "Not in scope" error is misleading -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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: -------------------------------------+------------------------------------- E.g., if I have something like `Maybe.maybeToList` in a module, which does not have such an import, I get the following error: Not in scope: ‘Maybe.maybeToList’ Which leads the user to conclude that the `Maybe` namespace does not contain the `maybeToList` element, instead of informing that the `Maybe` namespace is not imported altogether instead. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: The "Not in scope" error is misleading -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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 osa1): I don't understand why would anyone conclude from this message: {{{ Not in scope: NameSpace.name }}} that the namespace doesn't define the name. The message doesn't say anything about something being defined or not, it's very clearly saying that the name is not in scope. It may be because of different reasons. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: The "Not in scope" error is misleading -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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 mojojojo): Reference to a specific member implies that that particular member is the problem, while in reality it is the absence of the whole namespace that is the problem. In no way does the current message suggest that. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: The "Not in scope" error is misleading -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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 jstolarek): Replying to [comment:2 mojojojo]:
while in reality it is the absence of the whole namespace that is the problem
I disagree. If you have: ``` import Foo hiding ( bar ) ``` then `Foo` namespace is available, but any reference to `bar` will still result with "not in scope" error. I find the error message entirely correct and vote to close this ticket as "invalid". -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: The "Not in scope" error is misleading -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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 mojojojo): Replying to [comment:3 jstolarek]: You're missing the point here. The issue is that the message does not make sense specifically when the namespace is **not imported in any way**. It misleads the user to assume that it is imported but does not contain the member (or has it hidden), when the issue is absolutely different. Your example is simply not related to the issue. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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: | -------------------------------------+------------------------------------- Changes (by nomeata): * type: bug => feature request Comment: No need to get excited. We have a track of giving rather verbose error messages that try to convey as much information as possible to the user. So simply add any useful additional information, such as: {{{ Not in scope: ‘Maybe.maybeToList’ No Module named Maybe is imported. }}} or {{{ Not in scope: ‘Maybe.maybeToList’ Module `Maybe` does not provide `maybeToList` }}} or {{{ Not in scope: ‘Maybe.maybeToList’ Your import of `Maybe` explicitly hides `maybeToList`. }}} for the three cases I can think of why some `Foo.bar` is not in scope. This would indeed be useful, and helpful in any case. It’s also not completely trivial, as there is a many-to-many mapping of modules and modules name in scope, due to qualified imports. Nevertheless, this looks like a nice newcomer task. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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): I think comment:5 has it right. Adding supplementary hints to a failed use of a qualified name would be a fine thing to do. Not entirely trivial to implement: the `GlobalRdrEnv` records what ''is'' in scope, not what is ''not'' in scope. So you'd have to go back to the original imports. Quite do-able though. Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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 mojojojo): I absolutely agree with the suggestions by @nomeata as well. Thanks! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.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: | -------------------------------------+------------------------------------- Changes (by nomeata): * owner: => nomeata Old description:
E.g., if I have something like `Maybe.maybeToList` in a module, which does not have such an import, I get the following error:
Not in scope: ‘Maybe.maybeToList’
Which leads the user to conclude that the `Maybe` namespace does not contain the `maybeToList` element, instead of informing that the `Maybe` namespace is not imported altogether instead.
New description: E.g., if I have something like `Maybe.maybeToList` in a module, which does not have such an import, I get the following error: Not in scope: ‘Maybe.maybeToList’ Which leads the user to conclude that the `Maybe` namespace does not contain the `maybeToList` element, instead of informing that the `Maybe` namespace is not imported altogether instead -- Comment: Looking at the code right now. The first case (`No Module named Maybe is imported.`) is pretty easy. The other cases are actually quite tricky. The semantics of import lists is rather involved, and the code in `filterImports` in `RnNames` is quite terse. Maybe it is better to simply remember the `mi_exports` of all modules, look up the name there, and if it is found, then conclude that it was the fault of the import list. OTOH, a perfect solution would actually suggest to add `D3` to the `C(D1,D2,D3)` in `import Foo (C(D1,D2))` if a data constructor `Foo.D3` is out of scope. I’ll see how far I get... -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.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): Phab:D1462 Wiki Page: | -------------------------------------+------------------------------------- Changes (by nomeata): * status: new => patch * differential: => Phab:D1462 * milestone: => 8.0.1 Comment: Got something nice; I’m quite happy with it so far. Let’s see how many corner cases arise :-) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.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): Phab:D1462 Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): Looking at the code, it doesn't seem too difficult to also improve the error message for cases (3) and (4) (from comment:5) when using //unqualified// imports. For example: {{{ import Data.Map import Data.List hiding (transpose) f = transpose }}} This could show the same message as when `f = Data.List.transpose`: `"Perhaps you want to remove ‘transpose’ from the explicit hiding list in the import of ‘Data.List’"`, because only `Data.List` exports `transpose`; `Data.Map` doesn't. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.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): Phab:D1462 Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata): Yes, that idea crossed my mind as well. Would you suggest I include in Phab:D1462, or should we, in the interest of self-contained and reasonably sized patches land that first before I implement that variant as well? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.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): Phab:D1462 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Joachim Breitner <mail@…>): In [changeset:"e66f79dfb22031dd3f75dd3eb341e8269ab51d83/ghc" e66f79df/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="e66f79dfb22031dd3f75dd3eb341e8269ab51d83" Give helpful advice when a fully qualified name is not in scope This implements #11071. It needs to thread through a GlobalRdrEnv corresponding to the export list of the module if its exports were not restricted. A refactoring of ImportedModsVal into a proper data type follows. Differential Revision: https://phabricator.haskell.org/D1462 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.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): Phab:D1462 Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata): First version landed. I’ll leave this open to implement thomie’s suggestions (which will necessarily include a special case for this: {{{ foo is not in scope. You have not imported anything, not even Prelude. You are on your own! }}} (The more common, new cases will be: Printing nothing if no restricted import exists or no restricted import exports `foo`, and the usual list from above if one or more restricted unqualified import could be made to provide `foo`.) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:13> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.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): Phab:D1462 Wiki Page: | Phab:D1478 -------------------------------------+------------------------------------- Changes (by nomeata): * differential: Phab:D1462 => Phab:D1462 Phab:D1478 Comment: Thomie, how do you like Phab:D1478? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:14> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.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): Phab:D1462 Wiki Page: | Phab:D1478 -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"11e336e4a4f7a0c0319d9bfb1a6931a5861299cf/ghc" 11e336e4/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="11e336e4a4f7a0c0319d9bfb1a6931a5861299cf" More import related hints Now for unqualified imports. Improves upon #11071. Unfortunately, it seems that since 7.10, ghc will not print all out-of-scope errors. Test Plan: test suite updated Reviewers: austin, thomie, bgamari Reviewed By: bgamari Differential Revision: https://phabricator.haskell.org/D1478 GHC Trac Issues: #11071 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:15> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1462 Wiki Page: | Phab:D1478 -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed Comment: The errors arising from these situations should be greatly improved with nomeata's work. Let us know if you think they could be further improved. Closing this for now. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:16> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1462 Wiki Page: | Phab:D1478 -------------------------------------+------------------------------------- Comment (by thomie): Replying to [comment:14 nomeata]:
Thomie, how do you like Phab:D1478?
Perfect. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:17> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#11071: "Not in scope" errors should be more informative for qualified names. -------------------------------------+------------------------------------- Reporter: mojojojo | Owner: nomeata Type: feature request | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D1462 Wiki Page: | Phab:D1478 -------------------------------------+------------------------------------- Comment (by Joachim Breitner <mail@…>): In [changeset:"a586622c5386610e8ceffca7ef1efdf33d753587/ghc" a586622c/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="a586622c5386610e8ceffca7ef1efdf33d753587" Release Notes: Mention out-of-scope error message improvements Summary: as implemented for #11071. Differential Revision: https://phabricator.haskell.org/D1498 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11071#comment:18> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC