Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/dfmt/ast_info.d
Original file line number Diff line number Diff line change
Expand Up @@ -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!"")
Expand All @@ -479,8 +490,6 @@ final class FormatVisitor : ASTVisitor
}
}
}

functionCall.accept(this);
}

private:
Expand Down
4 changes: 3 additions & 1 deletion src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions tests/allman/issue0586.d.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
11 changes: 11 additions & 0 deletions tests/issue0586.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions tests/knr/issue0586.d.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions tests/otbs/issue0586.d.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}