diff --git a/src/dfmt/ast_info.d b/src/dfmt/ast_info.d index 34a8ede..7101471 100644 --- a/src/dfmt/ast_info.d +++ b/src/dfmt/ast_info.d @@ -454,14 +454,25 @@ final class FormatVisitor : ASTVisitor override void visit(const FunctionCallExpression functionCall) { - // Check if function has any arguments. - if (functionCall.arguments.namedArgumentList is null) + visit(functionCall.arguments); + functionCall.accept(this); + } + + override void visit(const NewExpression newCall) + { + visit(newCall.arguments); + newCall.accept(this); + } + + private void visit(const Arguments arguments) + { + // Check if call has any arguments. + if (!arguments || arguments.namedArgumentList is null) { - functionCall.accept(this); return; } - foreach (item; functionCall.arguments.namedArgumentList.items) + foreach (item; arguments.namedArgumentList.items) { // Do nothing if not a named argument. if (item.name == tok!"") @@ -479,8 +490,6 @@ final class FormatVisitor : ASTVisitor } } } - - functionCall.accept(this); } private: diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 0f7e821..2545edb 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -1783,6 +1783,8 @@ private: if (hasCurrent) { + const isNamedArg = index + 1 < tokens.length + && astInformation.namedArgumentColonLocations.canFindIndex(tokens[index + 1].index); if (currentIs(tok!"else")) { immutable i = indents.indentToMostRecent(tok!"if"); @@ -1791,7 +1793,7 @@ private: if (mostRecent != -1) indentLevel = mostRecent; } - else if (currentIs(tok!"identifier") && peekIs(tok!":")) + else if (currentIs(tok!"identifier") && peekIs(tok!":") && !isNamedArg) { if (peekBackIs(tok!"}", true) || peekBackIs(tok!";", true)) indents.popTempIndents(); diff --git a/tests/allman/issue0586.d.ref b/tests/allman/issue0586.d.ref index cd86519..1a33a3d 100644 --- a/tests/allman/issue0586.d.ref +++ b/tests/allman/issue0586.d.ref @@ -26,3 +26,9 @@ void main() temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); } + +void test() +{ + return Struct(foo: field.foo, bar: field.bar, baz: field.baz); + return new Class(foo: field.foo, bar: field.bar, baz: field.baz); +} diff --git a/tests/issue0586.d b/tests/issue0586.d index db744f3..3d8d32a 100644 --- a/tests/issue0586.d +++ b/tests/issue0586.d @@ -29,3 +29,14 @@ void main() temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); } + +void test() { + return Struct( + foo: field.foo, + bar: field.bar, + baz: field.baz); + return new Class( + foo: field.foo, + bar: field.bar, + baz: field.baz); +} diff --git a/tests/knr/issue0586.d.ref b/tests/knr/issue0586.d.ref index 76c61bc..2a6a6a3 100644 --- a/tests/knr/issue0586.d.ref +++ b/tests/knr/issue0586.d.ref @@ -25,3 +25,9 @@ void main() temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); } + +void test() +{ + return Struct(foo: field.foo, bar: field.bar, baz: field.baz); + return new Class(foo: field.foo, bar: field.bar, baz: field.baz); +} diff --git a/tests/otbs/issue0586.d.ref b/tests/otbs/issue0586.d.ref index e62ff1a..d6ab363 100644 --- a/tests/otbs/issue0586.d.ref +++ b/tests/otbs/issue0586.d.ref @@ -22,3 +22,8 @@ void main() { temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); } + +void test() { + return Struct(foo: field.foo, bar: field.bar, baz: field.baz); + return new Class(foo: field.foo, bar: field.bar, baz: field.baz); +}