Skip to content

Commit d37bea1

Browse files
committed
Adjust loc
1 parent 75e805d commit d37bea1

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4892,16 +4892,30 @@ and parse_type_constructor_declaration_with_bar p =
48924892
[doc_comment_to_attribute loc s]
48934893
| _ -> []
48944894
in
4895+
let has_doc_comment = not (doc_comment_attrs = []) in
48954896
match p.Parser.token with
48964897
| Bar ->
48974898
let start_pos = p.Parser.start_pos in
48984899
Parser.next p;
48994900
let constr = parse_type_constructor_declaration ~start_pos p in
4901+
let pcd_loc =
4902+
if has_doc_comment then
4903+
{
4904+
constr.Parsetree.pcd_loc with
4905+
loc_end =
4906+
{
4907+
constr.pcd_loc.loc_end with
4908+
pos_lnum = constr.pcd_loc.loc_end.pos_lnum + 1;
4909+
};
4910+
}
4911+
else constr.pcd_loc
4912+
in
49004913
Some
49014914
{
49024915
constr with
49034916
Parsetree.pcd_attributes =
49044917
doc_comment_attrs @ constr.Parsetree.pcd_attributes;
4918+
pcd_loc;
49054919
}
49064920
| _ -> None
49074921

@@ -4939,10 +4953,27 @@ and parse_type_constructor_declarations ?first p =
49394953
[doc_comment_to_attribute loc s]
49404954
| _ -> []
49414955
in
4956+
let has_doc_comment = not (doc_comment_attrs = []) in
49424957
let start_pos = p.Parser.start_pos in
49434958
ignore (Parser.optional p Token.Bar);
49444959
let constr = parse_type_constructor_declaration ~start_pos p in
4945-
{constr with pcd_attributes = doc_comment_attrs @ constr.pcd_attributes}
4960+
let pcd_loc =
4961+
if has_doc_comment then
4962+
{
4963+
constr.Parsetree.pcd_loc with
4964+
loc_end =
4965+
{
4966+
constr.pcd_loc.loc_end with
4967+
pos_lnum = constr.pcd_loc.loc_end.pos_lnum + 1;
4968+
};
4969+
}
4970+
else constr.pcd_loc
4971+
in
4972+
{
4973+
constr with
4974+
pcd_attributes = doc_comment_attrs @ constr.pcd_attributes;
4975+
pcd_loc;
4976+
}
49464977
| Some first_constr_decl -> first_constr_decl
49474978
in
49484979
first_constr_decl

compiler/syntax/src/res_printer.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ let print_listi ~get_loc ~nodes ~print ?(force_break = false) t =
352352
| Some comment -> (Comment.loc comment).loc_start
353353
in
354354
let sep =
355-
if start_pos.pos_lnum - prev_loc.loc_end.pos_lnum > 1 then Doc.hard_line
355+
if start_pos.pos_lnum - prev_loc.loc_end.pos_lnum > 1 then
356+
Doc.concat [Doc.hard_line; Doc.hard_line]
356357
else Doc.line
357358
in
358359
let doc = print_comments (print node t i) t loc in

0 commit comments

Comments
 (0)