Avoid interpreting named args as labels when indenting newline in keep_line_breaks mode.

This commit is contained in:
Mathis Beer 2025-09-25 11:14:32 +02:00 committed by Jan Jurzitza
parent d8e43e23ec
commit a12e83e8a4
5 changed files with 24 additions and 1 deletions

View File

@ -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();

View File

@ -26,3 +26,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);
}

View File

@ -29,3 +29,10 @@ 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);
}

View File

@ -25,3 +25,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);
}

View File

@ -22,3 +22,7 @@ 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);
}