File 2595-stdlib-Fix-pretty-printing-of-try-expressions.patch of Package erlang
From 19a4e25cad2be467d51e4a2d1888ef2253ef4171 Mon Sep 17 00:00:00 2001
From: Hans Bolinder <hasse@erlang.org>
Date: Wed, 29 Jan 2020 13:22:35 +0100
Subject: [PATCH 5/5] stdlib: Fix pretty printing of try-expressions
Blank lines were inserted by the Erlang pretty printer (erl_pp) when
formatting try-expressions with omitted catch- or after-clauses.
---
lib/stdlib/src/erl_pp.erl | 14 +++++++-------
lib/stdlib/test/erl_pp_SUITE.erl | 15 +++++++++++++++
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/lib/stdlib/src/erl_pp.erl b/lib/stdlib/src/erl_pp.erl
index 4a9244f7e3..daa172af50 100644
--- a/lib/stdlib/src/erl_pp.erl
+++ b/lib/stdlib/src/erl_pp.erl
@@ -658,20 +658,20 @@ lexpr({'try',_,Es,Scs,Ccs,As}, _, Opts) ->
true ->
{step,{list,[{step,'try',body(Es, Opts)},{reserved,'of'}]},
cr_clauses(Scs, Opts)}
- end,
+ end] ++
if
Ccs =:= [] ->
[];
true ->
- {step,'catch',try_clauses(Ccs, Opts)}
- end,
+ [{step,'catch',try_clauses(Ccs, Opts)}]
+ end ++
if
As =:= [] ->
[];
true ->
- {step,'after',body(As, Opts)}
- end,
- {reserved,'end'}]};
+ [{step,'after',body(As, Opts)}]
+ end ++
+ [{reserved,'end'}]};
lexpr({'catch',_,Expr}, Prec, Opts) ->
{P,R} = preop_prec('catch'),
El = {list,[{step,'catch',lexpr(Expr, R, Opts)}]},
@@ -983,7 +983,7 @@ frmt(Item, I, PP) ->
%%% - {prefer_nl,Sep,IPs}: forces linebreak between Is unlesss negative
%%% indentation.
%%% - {atom,A}: an atom
-%%% - {singleton_atom_type,A}: an singleton atom type
+%%% - {singleton_atom_type,A}: a singleton atom type
%%% - {char,C}: a character
%%% - {string,S}: a string.
%%% - {value,T}: a term.
diff --git a/lib/stdlib/test/erl_pp_SUITE.erl b/lib/stdlib/test/erl_pp_SUITE.erl
index 0dc315e7bb..48152243f8 100644
--- a/lib/stdlib/test/erl_pp_SUITE.erl
+++ b/lib/stdlib/test/erl_pp_SUITE.erl
@@ -1282,6 +1282,21 @@ otp_16435(_Config) ->
Check("fun foo:bar/17 #{}"),
Check("fun a/2 #{}"),
+ Check("try foo:bar() of\n"
+ " a ->\n"
+ " b\n"
+ "after\n"
+ " d\n"
+ "end"),
+
+ Check("try foo:bar() of\n"
+ " a ->\n"
+ " b\n"
+ "catch\n"
+ " _:_ ->\n"
+ " c\n"
+ "end"),
+
ok.
gh_5093(_Config) ->
--
2.16.4