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
get the name of a function from its body, in order to write precise error message #6887
Comments
Comment author: berenger Archives of the discussion on caml-list: I'll try to find back an even older thread. |
Comment author: berenger I am interested in this feature for logging purposes. |
Comment author: @gasche There are many questions on what "the current function" means.
let data_table =
let f x = let g x = x
let table = let build_table handle =
module F (X : Plugin) : strut end = struct For any of those cases (and I'm sure there are many others) the answer might be "fail (at parse time) in this corner case". I think that FUNCTION is maybe not the right intuition because there is a lot of code that may not be in a FUNCTION. Hongbo Zhang reported his implementation of a BIND syntax extension that would return the name of the toplevel binding above it (be it a function, toplevel binding, functor, whatever). Finally, how many RANDOM_STUFF are we going to add? It may be time of thinking of a single location-sensitive magic constant, eg. LOCATION (LOC is unfortunately already taken), with an abstract type and an access interface somewhere in the stdlib, so that we could arbitrary fields to it in the future if users demand. |
Comment author: berenger Just an idea: maybe %anonymous or %inlined could be a valid answer in some |
Comment author: berenger FUNCTION is not a random stuff. |
Comment author: @sliquister This can be implemented in a preprocessor, it's not clear why it should be in the compiler. |
Comment author: @damiendoligez Indeed, this should be an extension, for example [%function], interpreted by some ppx preprocessor. |
Comment author: Nimant "This can be implemented in a preprocessor, it's not clear why it should be in the compiler" I prefer not to use a preprocessor. I think this functionnality should be provided by any language. |
Comment author: @mshinwell It doesn't seem unreasonable to me to have this functionality without using a preprocessor. gasche's idea of some kind of magic constant sounds quite interesting. I don't think there is any problem with finding function names: it could just use the same names as the gdb branch assigns to functions based on the static scope. For the above examples:
This could be done before inlining to avoid any problems in that regard. |
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
Maybe one can reuse some of the work that went into #9096 ? |
Original bug ID: 6887
Reporter: Nimant
Status: acknowledged (set by @damiendoligez on 2015-06-05T21:09:22Z)
Resolution: open
Priority: normal
Severity: feature
Category: language features
Monitored by: @hcarty
Bug description
add a FUNCTION functionnality to provide the name of the current function. To be used in error messages.
The text was updated successfully, but these errors were encountered: