diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 004c0d5..050d8b6 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -431,6 +431,11 @@ private: } void formatLeftParenOrBracket() + in + { + assert(currentIs(tok!"(") || currentIs(tok!"[")); + } + body { immutable p = tokens[index].type; regenLineBreakHintsIfNecessary(index); @@ -464,15 +469,18 @@ private: } void formatRightParen() + in + { + assert(currentIs(tok!")")); + } + body { parenDepth--; if (parenDepth == 0) indents.popWrapIndents(); - if (parenDepth == 0 && (currentIs(tok!"out") || currentIs(tok!"body"))) - { + + if (parenDepth == 0 && (peekIs(tok!"in") || peekIs(tok!"out") || peekIs(tok!"body"))) writeToken(); - newline(); - } else if (peekIsLiteralOrIdent() || peekIsBasicType()) { writeToken(); @@ -770,7 +778,9 @@ private: if (!currentIs(tok!"{") && !currentIs(tok!";")) write(" "); } - else if (!currentIs(tok!"{") && !currentIs(tok!";")) + else if (!currentIs(tok!"{") && !currentIs(tok!";") + && !currentIs(tok!"in") && !currentIs(tok!"out") + && !currentIs(tok!"body")) newline(); } @@ -835,7 +845,10 @@ private: case tok!"in": immutable isContract = astInformation.contractLocations.canFindIndex(current.index); if (isContract) + { + indents.popTempIndents(); newline(); + } else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!")) write(" "); writeToken(); diff --git a/tests/allman/issue0209.d.ref b/tests/allman/issue0209.d.ref new file mode 100644 index 0000000..4e59b54 --- /dev/null +++ b/tests/allman/issue0209.d.ref @@ -0,0 +1,23 @@ +unittest +{ + { + public Vector!(T) opBinary(string op, string file = __FILE__, size_t line = __LINE__)( + const Vector!(T) x) const if (op == "*") + in + { + } + body + { + } + + } +} + +public Vector!(T) opBinary(string op, string file = __FILE__, size_t line = __LINE__)( + const Vector!(T) x) const if (op == "*") +in +{ +} +body +{ +} diff --git a/tests/issue0209.d b/tests/issue0209.d new file mode 100644 index 0000000..af39a20 --- /dev/null +++ b/tests/issue0209.d @@ -0,0 +1,21 @@ +unittest +{ + { + public Vector!(T) opBinary(string op, string file = __FILE__, size_t line = __LINE__)(const Vector!(T) x) const if (op == "*") + in + { + } + body + { + } + + } +} + +public Vector!(T) opBinary(string op, string file = __FILE__, size_t line = __LINE__)(const Vector!(T) x) const if (op == "*") +in +{ +} +body +{ +} diff --git a/tests/otbs/issue0209.d.ref b/tests/otbs/issue0209.d.ref new file mode 100644 index 0000000..aa64fe9 --- /dev/null +++ b/tests/otbs/issue0209.d.ref @@ -0,0 +1,18 @@ +unittest { + { + public Vector!(T) opBinary(string op, string file = __FILE__, size_t line = __LINE__)( + const Vector!(T) x) const if (op == "*") + in { + } + body { + } + + } +} + +public Vector!(T) opBinary(string op, string file = __FILE__, size_t line = __LINE__)( + const Vector!(T) x) const if (op == "*") +in { +} +body { +}