Skip to content

Commit ce1c20e

Browse files
committed
Fix #100
1 parent 0b7bc36 commit ce1c20e

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

src/dfmt.d

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,11 @@ private:
307307
else if ((isBlockHeader() || currentIs(tok!"version") || currentIs(tok!"debug"))
308308
&& peekIs(tok!"(", false))
309309
{
310-
immutable bool shouldPushIndent = (!currentIs(tok!"version")
311-
&& !currentIs(tok!"debug")) || astInformation.conditionalWithElseLocations
312-
.canFindIndex(current.index) || astInformation.conditionalStatementLocations.canFindIndex(
313-
current.index);
310+
immutable bool a = !currentIs(tok!"version") && !currentIs(tok!"debug") ;
311+
immutable bool b = a || astInformation.conditionalWithElseLocations
312+
.canFindIndex(current.index);
313+
immutable bool shouldPushIndent = b || astInformation.conditionalStatementLocations
314+
.canFindIndex(current.index);
314315
if (shouldPushIndent)
315316
indents.push(current.type);
316317
writeToken();
@@ -1764,7 +1765,7 @@ struct IndentStack
17641765
foreach (i; 1 .. j + 1)
17651766
{
17661767
if ((i + 1 <= index && !isWrapIndent(arr[i]) && isTempIndent(arr[i])
1767-
&& (!isTempIndent(arr[i + 1]))))
1768+
&& (!isTempIndent(arr[i + 1]) || arr[i + 1] == tok!"switch")))
17681769
{
17691770
continue;
17701771
}

tests/issue0100.d

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
unittest
2+
{
3+
loop: while (i < tokens.length) switch (tokens[i].type)
4+
{
5+
case tok!"(":
6+
parenDepth++;
7+
i++;
8+
break;
9+
case tok!"{":
10+
braceDepth++;
11+
i++;
12+
break;
13+
}
14+
}

tests/issue0100.d.ref

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
unittest
2+
{
3+
loop: while (i < tokens.length) switch (tokens[i].type)
4+
{
5+
case tok!"(":
6+
parenDepth++;
7+
i++;
8+
break;
9+
case tok!"{":
10+
braceDepth++;
11+
i++;
12+
break;
13+
}
14+
}

0 commit comments

Comments
 (0)