From d5eed6a9b06c4208a4894c434b67b0550f20c2cc Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Sun, 8 Mar 2015 18:23:01 -0700 Subject: [PATCH] Fix #70 --- src/dfmt.d | 22 ++++++++++++++-------- tests/issue0070.d | 9 +++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 tests/issue0070.d diff --git a/src/dfmt.d b/src/dfmt.d index 37dbe5e..591f965 100644 --- a/src/dfmt.d +++ b/src/dfmt.d @@ -468,10 +468,13 @@ private: if (ifIndents.length) ifIndents.pop(); } - else if (!peekIs(tok!"}")) - tempIndent = 0; - else - popIndent(); + else if (braceIndents.top() < tempIndent) + { + if (!peekIs(tok!"}")) + tempIndent = 0; + else + popIndent(); + } writeToken(); linebreakHints = []; if (index >= tokens.length || current.type != tok!"comment" @@ -604,12 +607,17 @@ private: /// Pushes a temporary indent level void pushIndent() { +// stderr.writeln("pushIndent: ", current.line, ",", current.column); tempIndent++; } /// Pops a temporary indent level void popIndent() { +// if (index < tokens.length) +// stderr.writeln("popIndent: ", current.line, ",", current.column); +// else +// stderr.writeln("popIndent: EOF"); if (tempIndent > 0) tempIndent--; } @@ -697,11 +705,11 @@ private: else if (current.type == tok!"}") { braceIndents.pop(); + depth--; if (assumeSorted(astInformation.structInitEndLocations) .equalRange(tokens[index].index).length) { writeToken(); - depth--; } else { @@ -709,7 +717,6 @@ private: if (peekBackIsLiteralOrIdent() || peekBackIs(tok!",")) newline(); write("}"); - depth--; if (index < tokens.length - 1 && assumeSorted(astInformation.doubleNewlineLocations) .equalRange(tokens[index].index).length && !peekIs(tok!"}")) @@ -732,7 +739,6 @@ private: formatStep(); } while (index < tokens.length && depth > 0); - popIndent(); } void writeParens(bool space_afterwards) @@ -801,7 +807,7 @@ private: formatStep(); } while (index < tokens.length && depth > 0); - popIndent(); +// popIndent(); tempIndent = t; linebreakHints = []; } diff --git a/tests/issue0070.d b/tests/issue0070.d new file mode 100644 index 0000000..0f6e1e4 --- /dev/null +++ b/tests/issue0070.d @@ -0,0 +1,9 @@ +unittest +{ + if (0) + if (0) + { + something(); + something_else(); + } +}