You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hmm, is changing Filename.chop_extension to Filename.remove_extension sufficient? It seems as if that will avoid raising the exception.
The code (specifically parse_mod_use_file) seems a bit suspicious to me. A module name is supposed to be generated from a filename, but strings that are not sane module names such as "@%" are allowed. In fact, fairly sane filenames like "foo-bar.ml" will "work" and produce a module that the user will not be able to name in OCaml code - that doesn't seem right.
I would guess that a module name should be parsed after whacking off the filename parts?
let parse_mod_use_file name lb =
let modname =
String.capitalize_ascii (Filename.chop_extension (Filename.basename name))
in ...
Clearly the intent of the modname calculation is to turn a valid filename into a valid module name, and as you say it does not work very well. I don't think a robust logic exists to do this name munging inside the compiler (debugger/command_line.ml has similar but more robust logic in convert_module).
If you feel inspired to write something more robust, I think it could go into utils/misc.ml. If you don't, then I think at least getting rid of the failure here would be nice. Indeed Filename.remove_extension should be enough, I guess it did not exist at the time parse_mod_use_file was written.
Original bug ID: 7867
Reporter: ggole
Assigned to: @gasche
Status: resolved (set by @gasche on 2018-10-27T15:32:49Z)
Resolution: fixed
Priority: normal
Severity: crash
Version: 4.06.1
Fixed in version: 4.08.0+dev/beta1/beta2
Category: toplevel
Monitored by: @nojb @gasche
Bug description
When #mod_use is used with an argument that names a file that exists, and the name has no extension, the toplevel will die with an exception:
Fatal error: exception Invalid_argument("Filename.chop_extension")
Note that this does not happen if the named file does not exist.
Steps to reproduce
$ touch wat
$ ocaml
OCaml version 4.06.1
#mod_use "wat";;
Fatal error: exception Invalid_argument("Filename.chop_extension")
$
The text was updated successfully, but these errors were encountered: