From 49612a48a6ffac299fceb5444b9cf2cbe30031f2 Mon Sep 17 00:00:00 2001 From: Mathis Beer Date: Thu, 25 Sep 2025 17:34:54 +0200 Subject: [PATCH] Track 'new' expressions in the named argument offset list as well. --- src/dfmt/ast_info.d | 21 +++++++++++++++------ tests/allman/issue0586.d.ref | 1 + tests/issue0586.d | 4 ++++ tests/knr/issue0586.d.ref | 1 + tests/otbs/issue0586.d.ref | 1 + 5 files changed, 22 insertions(+), 6 deletions(-) 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/tests/allman/issue0586.d.ref b/tests/allman/issue0586.d.ref index d2d7847..1a33a3d 100644 --- a/tests/allman/issue0586.d.ref +++ b/tests/allman/issue0586.d.ref @@ -30,4 +30,5 @@ void main() 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 c786255..3d8d32a 100644 --- a/tests/issue0586.d +++ b/tests/issue0586.d @@ -35,4 +35,8 @@ void test() { 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 8b0b9f0..2a6a6a3 100644 --- a/tests/knr/issue0586.d.ref +++ b/tests/knr/issue0586.d.ref @@ -29,4 +29,5 @@ void main() 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 802f62c..d6ab363 100644 --- a/tests/otbs/issue0586.d.ref +++ b/tests/otbs/issue0586.d.ref @@ -25,4 +25,5 @@ void main() { 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); }