Skip to content

Commit 7ad3289

Browse files
committed
PR#7037: fix erroneous Location.input_name setting in Pparse.file
When reading a serialized-ast file, Pparse.file sets Location.input_name to the filename embedded in the AST, and this is correct. But before this patch it would also set Location.input_name to the filename if this is a regular file, and this is wrong: this filename may be a temporary file used for preprocessing (-pp option), with a randomly-generated name, while Location.input_name is in fact already correctly set to the user-provided source path. I needed to fix two lines in ocamldoc/odoc_analyze.ml that used !Location.input_file but actually required access to the post-processing file (ocamldoc re-opens source files and rereads them to detect documentation comments). This is not an invasive change as the path to the post-processing file is available at this point in the code (as the [input_file] variable). This ocamldoc issue was caught thanks to Debian downstream work in bug triaging ( mlpost breaks if it is not fixed, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=802347 ) and package maintenance (this bug would not have been found if Debian maintainers had not kept the mlpost documentation generator working even after non-trivial ocamldoc changes).
1 parent ab169aa commit 7ad3289

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

driver/pparse.ml

-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ let file_aux ppf ~tool_name inputfile (type a) parse_fun invariant_fun
178178
(input_value ic : a)
179179
end else begin
180180
seek_in ic 0;
181-
Location.input_name := inputfile;
182181
let lexbuf = Lexing.from_channel ic in
183182
Location.init lexbuf inputfile;
184183
parse_fun lexbuf

ocamldoc/odoc_analyse.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ let process_file sourcefile =
164164
None
165165
| Some (parsetree, typedtree) ->
166166
let file_module = Ast_analyser.analyse_typed_tree file
167-
!Location.input_name parsetree typedtree
167+
input_file parsetree typedtree
168168
in
169169
file_module.Odoc_module.m_top_deps <- Odoc_dep.impl_dependencies parsetree ;
170170

@@ -192,7 +192,7 @@ let process_file sourcefile =
192192
try
193193
let (ast, signat, input_file) = process_interface_file file in
194194
let file_module = Sig_analyser.analyse_signature file
195-
!Location.input_name ast signat.sig_type
195+
input_file ast signat.sig_type
196196
in
197197

198198
file_module.Odoc_module.m_top_deps <- Odoc_dep.intf_dependencies ast ;

0 commit comments

Comments
 (0)