Merge pull request #318 from dlang-community/issue_314

Issue 314
This commit is contained in:
Brian Schott 2018-01-29 19:52:33 -08:00 committed by GitHub
commit 0a351990c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 16 deletions

View File

@ -19,18 +19,18 @@ environment:
- DC: dmd - DC: dmd
DVersion: stable DVersion: stable
arch: x86 arch: x86
- DC: ldc # - DC: ldc
DVersion: beta # DVersion: beta
arch: x86 # arch: x86
- DC: ldc # - DC: ldc
DVersion: beta # DVersion: beta
arch: x64 # arch: x64
- DC: ldc # - DC: ldc
DVersion: stable # DVersion: stable
arch: x86 # arch: x86
- DC: ldc # - DC: ldc
DVersion: stable # DVersion: stable
arch: x64 # arch: x64
skip_tags: false skip_tags: false
branches: branches:

View File

@ -841,7 +841,8 @@ private:
justAddedExtraNewline = true; justAddedExtraNewline = true;
} }
if (config.dfmt_brace_style == BraceStyle.otbs if (config.dfmt_brace_style == BraceStyle.otbs
&& peekIs(tok!"else") && !indents.topAre(tok!"static", tok!"if")) && peekIs(tok!"else") && !indents.topAre(tok!"static", tok!"if")
&& !indents.topIs(tok!"foreach"))
{ {
write(" "); write(" ");
index++; index++;
@ -852,7 +853,7 @@ private:
&& !peekIs(tok!";") && !peekIs(tok!"{")) && !peekIs(tok!";") && !peekIs(tok!"{"))
{ {
index++; index++;
if (indents.topIs(tok!"static")) if (indents.topIsOneOf(tok!"static", tok!"foreach"))
indents.pop(); indents.pop();
newline(); newline();
} }

View File

@ -159,14 +159,17 @@ struct IndentStack
return cast(int) index; return cast(int) index;
} }
/+void dump() /**
* Dumps the current state of the indentation stack to `stderr`. Used for debugging.
*/
void dump()
{ {
import std.stdio : stderr; import std.stdio : stderr;
import dparse.lexer : str; import dparse.lexer : str;
import std.algorithm.iteration : map; import std.algorithm.iteration : map;
stderr.writefln("\033[31m%(%s %)\033[0m", arr[0 .. index].map!(a => str(a))); stderr.writefln("\033[31m%(%s %)\033[0m", arr[0 .. index].map!(a => str(a)));
}+/ }
private: private:

View File

@ -0,0 +1,11 @@
void main()
{
auto d = {
if (a)
foreach (b; c)
{
}
else
e();
};
}

9
tests/issue0314.d Normal file
View File

@ -0,0 +1,9 @@
void main()
{
auto d = {
if (a)
foreach (b; c) { }
else
e();
};
}

View File

@ -0,0 +1,9 @@
void main() {
auto d = {
if (a)
foreach (b; c) {
}
else
e();
};
}