@@ -4120,7 +4120,13 @@ and printPexpApply ~state expr cmtTbl =
41204120 let partial, attrs = ParsetreeViewer. processPartialAppAttribute attrs in
41214121 let args =
41224122 if partial then
4123- let dummy = Ast_helper.Exp. constant (Ast_helper.Const. int 0 ) in
4123+ let loc =
4124+ {Asttypes. txt = " res.partial" ; Asttypes. loc = expr.pexp_loc}
4125+ in
4126+ let attr = (loc, Parsetree. PTyp (Ast_helper.Typ. any () )) in
4127+ let dummy =
4128+ Ast_helper.Exp. constant ~attrs: [attr] (Ast_helper.Const. int 0 )
4129+ in
41244130 args @ [(Asttypes. Labelled " ..." , dummy)]
41254131 else args
41264132 in
@@ -4700,6 +4706,18 @@ and printArguments ~state ~dotted ?(partial = false)
47004706 Doc. concat
47014707 [(if dotted then Doc. text " (. " else Doc. lparen); argDoc; Doc. rparen]
47024708 | args ->
4709+ (* Avoid printing trailing comma when there is ... in function application *)
4710+ let hasPartialAttr, printedArgs =
4711+ List. fold_right
4712+ (fun arg (flag , acc ) ->
4713+ let _, expr = arg in
4714+ let hasPartialAttr =
4715+ ParsetreeViewer. hasPartialAttribute expr.Parsetree. pexp_attributes
4716+ in
4717+ let doc = printArgument ~state arg cmtTbl in
4718+ (flag || hasPartialAttr, doc :: acc))
4719+ args (false , [] )
4720+ in
47034721 Doc. group
47044722 (Doc. concat
47054723 [
@@ -4708,11 +4726,9 @@ and printArguments ~state ~dotted ?(partial = false)
47084726 (Doc. concat
47094727 [
47104728 (if dotted then Doc. line else Doc. softLine);
4711- Doc. join
4712- ~sep: (Doc. concat [Doc. comma; Doc. line])
4713- (List. map (fun arg -> printArgument ~state arg cmtTbl) args);
4729+ Doc. join ~sep: (Doc. concat [Doc. comma; Doc. line]) printedArgs;
47144730 ]);
4715- (if partial then Doc. nil else Doc. trailingComma);
4731+ (if partial || hasPartialAttr then Doc. nil else Doc. trailingComma);
47164732 Doc. softLine;
47174733 Doc. rparen;
47184734 ])
0 commit comments