Don't indent associative array keys as labels

This commit is contained in:
Eugen Wissner 2021-03-09 10:46:32 +01:00 committed by The Dlang Bot
parent c4b6a7e7e3
commit 1f21a97713
5 changed files with 26 additions and 2 deletions

View File

@ -1694,8 +1694,8 @@ private:
assert(l2 != -1, "Recent '{' is not found despite being in struct initializer");
indentLevel = l2 + 1;
}
else if (config.dfmt_compact_labeled_statements == OptionalBoolean.f
|| !isBlockHeader(2) || peek2Is(tok!"if"))
else if ((config.dfmt_compact_labeled_statements == OptionalBoolean.f
|| !isBlockHeader(2) || peek2Is(tok!"if")) && !indents.topIs(tok!"]"))
{
immutable l2 = indents.indentToMostRecent(tok!"{");
indentLevel = l2 != -1 ? l2 : indents.indentLevel - 1;

View File

@ -0,0 +1,8 @@
void main()
{
string key;
int[string] var = [
key: 5
];
}

View File

@ -0,0 +1 @@
--keep_line_breaks=true

8
tests/assoc_key_indent.d Normal file
View File

@ -0,0 +1,8 @@
void main()
{
string key;
int[string] var = [
key: 5
];
}

View File

@ -0,0 +1,7 @@
void main() {
string key;
int[string] var = [
key: 5
];
}