From f1da7c3ba641f04fbb8345430f7ff60428dbe39a Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 8 Feb 2021 07:43:16 +0100 Subject: [PATCH] Don't write a space after the return attribute Fixes #521. --- src/dfmt/formatter.d | 4 +++- tests/allman/issue0521.d.ref | 17 +++++++++++++++++ tests/issue0521.d | 17 +++++++++++++++++ tests/otbs/issue0521.d.ref | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/allman/issue0521.d.ref create mode 100644 tests/issue0521.d create mode 100644 tests/otbs/issue0521.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 74821bf..696b4f8 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -224,7 +224,9 @@ private: else if (currentIs(tok!"return")) { writeToken(); - if (!currentIs(tok!";") && !currentIs(tok!")") && !currentIs(tok!"{")) + if (!currentIs(tok!";") && !currentIs(tok!")") && !currentIs(tok!"{") + && !currentIs(tok!"in") && !currentIs(tok!"out") && !currentIs(tok!"do") + && (hasCurrent && tokens[index].text != "body")) write(" "); } else if (currentIs(tok!"with")) diff --git a/tests/allman/issue0521.d.ref b/tests/allman/issue0521.d.ref new file mode 100644 index 0000000..67a0942 --- /dev/null +++ b/tests/allman/issue0521.d.ref @@ -0,0 +1,17 @@ +public int f() return +in (true) +{ + return 0; +} + +public int g() return +out (; true) +{ + return 0; +} + +public int h() return +body +{ + return 0; +} diff --git a/tests/issue0521.d b/tests/issue0521.d new file mode 100644 index 0000000..67a0942 --- /dev/null +++ b/tests/issue0521.d @@ -0,0 +1,17 @@ +public int f() return +in (true) +{ + return 0; +} + +public int g() return +out (; true) +{ + return 0; +} + +public int h() return +body +{ + return 0; +} diff --git a/tests/otbs/issue0521.d.ref b/tests/otbs/issue0521.d.ref new file mode 100644 index 0000000..14f0645 --- /dev/null +++ b/tests/otbs/issue0521.d.ref @@ -0,0 +1,14 @@ +public int f() return +in (true) { + return 0; +} + +public int g() return +out (; true) { + return 0; +} + +public int h() return +body { + return 0; +}