diff --git a/src/dfmt.d b/src/dfmt.d index f7c6d3d..0359721 100644 --- a/src/dfmt.d +++ b/src/dfmt.d @@ -316,7 +316,7 @@ private: writeToken(); if (current.type == tok!"if" || (current.type == tok!"static" && peekIs(tok!"if"))) write(" "); - else if (current.type != tok!"{") + else if (current.type != tok!"{" && current.type != tok!"comment") { pushIndent(); newline(); @@ -677,8 +677,10 @@ private: && !peekBackIs(tok!"}") && !peekBackIs(tok!";")) { if (config.braceStyle == BraceStyle.otbs) + { write(" "); - else + } + else if (!peekBackIs(tok!"comment") || tokens[index - 1].text[0 .. 2] != "//") newline(); } write("{"); @@ -711,7 +713,6 @@ private: } if (config.braceStyle == BraceStyle.otbs) { - index++; if (index < tokens.length && current.type == tok!"else") write(" "); } diff --git a/tests/issue0051.d b/tests/issue0051.d new file mode 100644 index 0000000..d4000a5 --- /dev/null +++ b/tests/issue0051.d @@ -0,0 +1,15 @@ +void f() +{ + if (a) + { + } + else // wat + { + if (!is_temp_arg_ref) + { + if (global.params.isOSX) + buf.writeByte('_'); + } + } + return; +} diff --git a/tests/issue0051.d.ref b/tests/issue0051.d.ref new file mode 100644 index 0000000..2563e6c --- /dev/null +++ b/tests/issue0051.d.ref @@ -0,0 +1,15 @@ +void f() +{ + if (a) + { + } + else // wat + { + if (!is_temp_arg_ref) + { + if (global.params.isOSX) + buf.writeByte('_'); + } + } + return; +}