New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toplevel: Show hints for the "undefined global" error #10647
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea and I think the messages you suggest are good. (See minor code comment.)
(A Changes entry would be nice.)
5eb2412
to
5888b81
Compare
I'm still not sure if "This means a module's interface is loaded, but its implementation is not" is always true and if the |
5888b81
to
0c167cb
Compare
It's an interesting idea to add hints for errors reported by the toplevel interactive loop. However, What about extending the toplevel so that it reports errors not just by calling |
Another option would be to override the |
This could work too. @wiktorkuchta : are you willing to explore these alternate approaches? |
14ca6c9
to
a364a17
Compare
Moved the code to However, it's still code specific to the bytecode backend (and won't be hit by the native toplevel unless it somehow raises the |
a364a17
to
bbf114a
Compare
This patch would give the correct hint for https://discuss.ocaml.org/t/wheres-the-unix-library/8782. Though while testing with |
bbf114a
to
2614386
Compare
@Octachron ping |
toplevel/topcommon.ml
Outdated
end; | ||
fprintf ppf "@]" | ||
end | ||
| _ -> () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This printer, given the way it is registered, claims to support all Symtable.Error
cases, but in fact ignores all errors that are not Undefined_global
. This is awkward and also probably wrong. I would feel safer if the loading_hint_printer
was passed directly to register_error_of_exn
, and would return Some
only in the case that it definitely knows how to handle better than the standard printers.
toplevel/topcommon.ml
Outdated
"@.Hint: @[\ | ||
This means a module's interface is loaded, \ | ||
but its implementation is not.@,"; | ||
begin match List.find_map find_with_ext [".cma"; ".cmo"] with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: in general there is no reason for foo.cma
to provide an implementation of the module Foo
, and this makes this heuristic frustratingly incomplete. It is very wrong in the general case, but also correct surprisingly often (Dynlink, Unix, Graphics etc.). I would keep the code as you wrote it, but include a comment to point out that hinting at the .cma may be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with the refactored implementation. Thanks!
(You could squash/fixup the commits together, to save us from the annoying github UI to do it at merge time.)
This PR adds hints for loading modules when hitting the "undefined global" error. The advice is basically taken from the toplevel chapter of the manual, but we can make it a bit more helpful because we can see what files are already there (in the load paths).
For example, this is the hint in the following (possibly confusing for the user) interaction:
The advice with the
.ml
file in the code might be not as useful, because it probably only fires if there is a.cmi
file but no.cmo
file, so I don't know whether to keep it.I realize the code looks repetitive, but the clever ways to rewrite it I can think of don't feel right and don't save much code.